Trouble with :FindFirstChild in server sided script

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(, PosY, PosZ)) -- Moves the unit to desiganted place
			print("Unit moved!")

So this implies that you add the playersTurn to the character on the client correct

Well I use a module script for that, but I’ve tried inserting the part directly into the player while tesing.

If the module is being ran on the client, and you didn’t change the mode to CurrentServer while testing, then the server cannot find the part because it’s not there for it

1 Like

The module script is being ran through a script in the workplace, does that count as running on the client? (A bit new to module script, and the relations between client and server sorry)
And also, the reason inserting the part into the player did not work was due to your reasoning. That one was on me.

1 Like

As long as it’s a script and not a LocalScript it is server sided

1 Like