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

Why my script works only in studio and not on my sever?

Asked by 8 years ago

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)

1 answer

Log in to vote
0
Answered by 8 years ago

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.

0
Works thx WITKOSKI 2 — 8y
Ad

Answer this question