Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this script only work in studio mode?

Asked by
Seraine 103
9 years ago

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)

0
What kind of script are you using? Local or Normal. YasuYoshida 171 — 9y

1 answer

Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

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

repeat wait(.5) until game.Players.LocalPlayer ~= nil
0
Thank you! Seraine 103 — 9y
Ad

Answer this question