Hello fellow developers!
I’m currently scripting a server sided script which will move an unit, and I’ve set up some verifications within the server sided script. These verifications will try and look for certain parts in a players character which I’m using FindFirstChild() in order to find.
The issue is that the script cannot find these parts. I’ve tried using WaitForChild(), but this just results in an infinite yield. Removing the if statements makes the script work as intended, though this would remove the verifications, allowing exploiters to exploit the script.
Here is the code used, located in ServerScriptStorage:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local ShowMovementRemoteEvent = ReplicatedStorage.RemoteEvents.Area1.RegisterUnitMovement ShowMovementRemoteEvent.OnServerEvent:Connect(function(Player, SelectedUnit, PosY, PosZ, PosX, MouseTarget) if Player.Character:FindFirstChild("PlayersTurn") then -- To check if it's the players turn (In order to avoid exploits) if MouseTarget.Parent:FindFirstChild("IsUnit") then -- To check if the target is actually an unit, so you can't move other players SelectedUnit:PivotTo(CFrame.new(PosX, PosY, PosZ)) -- Moves the unit to desiganted place print("Unit moved!") end end end)