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

Works with Play Solo but not on the Server?

Asked by 10 years ago
local localPlayer = game.Players.LocalPlayer
local char = localPlayer.Character
local humanoid = char:findFirstChild("Humanoid")
local torso = char:WaitForChild("Torso")

Mouse = localPlayer:GetMouse() --Body Turn Gyro Stuff
game:GetService("UserInputService").MouseIconEnabled = false
BodyGyro = Instance.new("BodyGyro", torso)
BodyGyro.maxTorque = Vector3.new(1,math.huge,1)

Mouse.Move:connect(function()
    print("Moving")
BodyGyro.cframe=Mouse.Hit
end)

Thanks, Off

2 answers

Log in to vote
0
Answered by 10 years ago

I put this into StarterGui and it worked fine. If it's in Workspace move it somewhere else, LocalScripts do not work in Workspace.

Ad
Log in to vote
0
Answered by 10 years ago
wait(.5)
local localPlayer = game.Players.LocalPlayer
local char = localPlayer.Character
local humanoid = char:findFirstChild("Humanoid")
local torso = char:WaitForChild("Torso")

Mouse = localPlayer:GetMouse() --Body Turn Gyro Stuff
game:GetService("UserInputService").MouseIconEnabled = false
BodyGyro = Instance.new("BodyGyro", torso)
BodyGyro.maxTorque = Vector3.new(1,math.huge,1)

Mouse.Move:connect(function()
    print("Moving")
BodyGyro.cframe=Mouse.Hit
end)

Reasoning: In studio almost all scripts are treated as local scripts and can call instances/functions that regular scripts can't if it's not in studio. If it's a local script in a locally acceptable area such as Backpack or PlayerGui than it's because local scripts load faster than your character so by the time the local script is done your character hasn't loaded properly. To prevent this I added a wait(.5) as a stopped to let everything load properly.

Thumbs up if this helps!

Answer this question