Last active
June 24, 2023 04:36
-
-
Save verticalgrain/d81556dad6e9c58ea4b10612d4b10ddf to your computer and use it in GitHub Desktop.
Roblox localscript examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Place this LocalScript inside a part in the Workspace or a child of the player's character | |
-- Constants | |
local PLAYER = game.Players.LocalPlayer | |
local Z_KEY_CODE = Enum.KeyCode.Z | |
local BLOCK_COLOR = BrickColor.new("Bright red") | |
-- Create the block | |
local block = Instance.new("Part") | |
block.Size = Vector3.new(2, 2, 2) | |
block.BrickColor = BLOCK_COLOR | |
block.Anchored = true | |
block.CanCollide = true | |
block.Parent = workspace | |
-- Function to handle key press | |
local function onKeyPress(input) | |
if input.KeyCode == Z_KEY_CODE then | |
local character = PLAYER.Character | |
if character then | |
-- Calculate the position where the block should appear | |
local position = character.HumanoidRootPart.Position + Vector3.new(0, 5, 0) -- Adjust the Y offset as needed | |
-- Clone the block and set its position | |
local newBlock = block:Clone() | |
newBlock.Position = position | |
newBlock.Parent = workspace | |
end | |
end | |
end | |
-- Connect the key press event | |
game:GetService("UserInputService").InputBegan:Connect(onKeyPress) | |
local player = game.Players.LocalPlayer | |
local userInputService = game:GetService("UserInputService") | |
local function onKeyPress(input) | |
if input.KeyCode == Enum.KeyCode.Z then | |
player.Character.Humanoid.Health = 0 | |
end | |
end | |
userInputService.InputBegan:Connect(onKeyPress) | |
local fartSoundId = "rbxassetid://123456789" -- Replace with the ID of the fart sound asset | |
local function onKeyPress(input) | |
if input.KeyCode == Enum.KeyCode.F then -- Change 'F' to the desired key | |
local character = game.Players.LocalPlayer.Character | |
local humanoid = character:FindFirstChild("Humanoid") | |
if humanoid then | |
local sound = Instance.new("Sound") | |
sound.SoundId = fartSoundId | |
sound.Parent = character:FindFirstChild("Head") | |
sound:Play() | |
-- Optional: Emit a particle effect | |
local fartEffect = Instance.new("Part") | |
fartEffect.Parent = workspace | |
fartEffect.Size = Vector3.new(2, 2, 2) | |
fartEffect.Position = character.HumanoidRootPart.Position | |
fartEffect.Transparency = 1 | |
local fartParticle = Instance.new("ParticleEmitter") | |
fartParticle.Parent = fartEffect | |
fartParticle.Texture = "rbxassetid://123456789" -- Replace with the ID of the fart particle texture | |
fartParticle:Emit(100) -- Number of particles emitted | |
wait(2) -- Adjust the duration of the fart sound and particle effect here | |
sound:Stop() | |
sound:Destroy() | |
fartEffect:Destroy() | |
end | |
end | |
end | |
game:GetService("UserInputService").InputBegan:Connect(onKeyPress) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment