I’m trying to make a script that plays an animation and a sound whenever the player presses G, but i can’t get it to work so other people can see it. It works as a client side script, though
local plr = script.Parent
local UIS = game:GetService("UserInputService")
local cool = false
UIS.InputBegan:connect(function(input,gameProcessedEvent)
if gameProcessedEvent then return end
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.G then
if cool == false then
cool = true
local taunts = {12257670484, 12257760662, 12257765298, 12257771364, 12257778055, 12257785007, 12257829096, 12644599453, 12644639245, 12644679613, 12644715935}
local taunt = Instance.new("Animation")
taunt.Name = "Taunt"
taunt.Parent = plr
taunt.AnimationId = string.format("rbxassetid://%d", taunts[math.random(1, #taunts)])
local Humanoid = plr.Humanoid
local tauntanim = Humanoid:LoadAnimation(taunt)
tauntanim.Priority = Enum.AnimationPriority.Action4 -- makes sure you can see the animation uninterrupted
tauntanim.Looped = false -- just in case i accidentally tick loop
tauntanim:Play()
local sound = script.Sound:Clone()
local particle = script.ParticleEmitter:Clone()-- for extra sauce
particle.Enabled = true
local random = math.random(1,7)
if random == 1 then -- this is probably the worst way to do this lol
sound.PlaybackSpeed = sound.PlaybackSpeed + 0
end
if random == 2 then
sound.PlaybackSpeed = sound.PlaybackSpeed + 0.05
end
if random == 3 then
sound.PlaybackSpeed = sound.PlaybackSpeed - 0.05
end
if random == 4 then
sound.PlaybackSpeed = sound.PlaybackSpeed + 0.02
end
if random == 5 then
sound.PlaybackSpeed = sound.PlaybackSpeed - 0.02
end
if random == 6 then
sound.PlaybackSpeed = sound.PlaybackSpeed + 0.15
end
if random == 7 then
sound.PlaybackSpeed = sound.PlaybackSpeed - 0.15
end
particle.Parent = plr.Torso
sound.Parent = plr.Head
plr.HumanoidRootPart.Anchored = true -- pause player's movement
sound:Play()
wait(0.1)
particle.Enabled = false
wait(0.1)
plr.HumanoidRootPart.Anchored = false -- resumes the player's movement
particle:Destroy()
wait(1) -- a lot of waits but it smooths out the effects a bit
sound:Destroy()
tauntanim:Destroy()
cool = false
end
end
end
end)
-- and we are done
i’ve tried loads of ways but i could never find a way to get it to work for everyone. Any ideas?