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

Studdery movement because of code issue?

Asked by 3 years ago

Okay, so I'm trying to make an enemy that only moves when everybody is not looking. However, that is more easily said than done. First, I check it the HumanoidRootPart of the enemy is in view of the local camera and send it via RemoteEvent to the server. Then, when it gets the message, it either sets the walk speed of the Humanoid to 0 or the enemy default. However, as soon as this turns multiplayer, that's when the stutter begins. It only stutters when one person is looking at it and the other is not. Is there any way to fix this??? Oh, and here is the server's side of things.

--Bool means the value i send that tells it whether or not it is in my vision.
game.ReplicatedStorage.SeenEvent.OnServerEvent:Connect(function(player,bool,object)
    if object.Name == "Creep" then --This is the one i am asking questions about
        if bool then
            object.Humanoid.WalkSpeed = 0
        else
            object.Humanoid.WalkSpeed = 12
        end
    elseif object.Name == "Danger" then
        if bool then
            object.Humanoid.WalkSpeed = 30
        else
            object.Humanoid.WalkSpeed = 0
        end
    end
end)

Answer this question