PlayerScripts Not Being found & player returning as nil

I want to make something true when the player touches a object, however sometimes plr returns as nil, and PlayerScripts is never found.

manusRegion = script.Parent
manusRegion.Touched:Connect(function(hit)
humanoid = hit.Parent
if humanoid then
	print("f")
	plr = game.Players:GetPlayerFromCharacter(humanoid)
	plrscripts = plr:WaitForChild("PlayerScripts")
	plrscripts.ManusEffectScreenShake.EsTrue.Value = true
	end
end)
3 Likes

PlayerScripts is not visible to the server as it is a container created by the client for client-side scripts. It is unable to see or access PlayerScripts in any way. This is assuming this code is on the server. You will need a different way to give the script or activate it.

You should also check if the player actually exists, as GetPlayerFromCharacter can return nil. You assume a truthy value is returned from this function call.

local plr = game:GetService("Players"):GetPlayerFromCharacter(humanoid)
if plr then
    -- Yes player exists
end
3 Likes

You should check if Humnaoid exists then call your function also I would do it like this:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then

local humanoid = workspace[hit.Parent.Name]
if humanoid then
	print("f")
	local plr = game.Players[tostring(humanoid)]
	local plrscripts = plr:FindFirstChild("PlayerScripts")
	plrscripts.ManusEffectScreenShake.EsTrue.Value = true
    end
  end
end)

You should use FindFirstChild at getting PlayerScripts folder because before player even touches the object is already in it. Oh and also you won’t be able to get PlayerScripts from character so I’d recommend you to call it from players.