So my script works in studio but when I run it on the server dose't work. how do I fix this code?
thing = nil function onButton1Down(mouse) local Hit = mouse.hit local MT = mouse.target if Hit==nil then return end if MT==nil then return end if MT.Parent:findFirstChild("Humanoid") ~= nil then thing = MT.Parent.Humanoid elseif MT.Parent:findFirstChild("Humanoid") ~= nil then thing = MT.Parent.Zombie else if thing ~= nil then thing:MoveTo(mouse.hit.p, MT) end end end function onS(mouse) mouse.Button1Down:connect(function() onButton1Down(mouse) end) end script.Parent.Selected:connect(onS)
I'm guessing from the Selected
event that this is in a HopperBin; in that case, you should put your code in a LocalScript rather than a regular script. Code in local scripts will run on the client and have access to things like the player's mouse. In studio, most code runs like it's on the client.