Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this script only work in studio mode?

Okay so this script works fine when I go to test > play solo, but when I click play the game in server mode, the script doesn't do anything... Help?

player=script.Parent.Parent.Parent 
char=player.Character
mouse=player:GetMouse()

dance_sound = Instance.new("Sound", char.head)
dance_sound.Name = "dance_sound"
dance_sound.Volume = 1
dance_sound.Looped = true

local dancestat = false

local danceanim = Instance.new("Animation", char)
danceanim.Name = "dance_anim"

mouse.KeyDown:connect(function(key) local key=key:lower()
if key=="e" then
danceanim.AnimationId = script.Parent.dance_anim.Value
local vCharacter = char
local hum = vCharacter:findFirstChild("Humanoid")
playanim = hum:LoadAnimation(char.dance_anim)
playanim:Play()
end
end)
mouse.KeyUp:connect(function(key) local key=key:lower()
if key=="e" then
playanim:Stop()
end
end)
mouse.KeyDown:connect(function(key) local key=key:lower()
if key=="e" then
dance_sound.SoundId = script.Parent.dance_sound.Value
dancestat = true
dance_sound:Play()
end
end)
mouse.KeyUp:connect(function(key) local key=key:lower()
if key=="e" then
dancestat = false
dance_sound:Stop()
end
end)

1 comment

0

What kind of script are you using? Local or Normal.

1 answer

✓ Accepted answer

On line 01, insert this code to let the script wait until the player is rendered:

repeat wait(.5) until game.Players.LocalPlayer ~= nil

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.