Why does this happen inside my script

I made a script whereas the player goes inside a part that has cancollide off and when the player enters it a value inside them gets changed, but i get this error whenever i go inside it, does anyone know why?

script.Parent.Touched:Connect(function(part)
	local plr = game.Players:GetPlayerFromCharacter(part.Parent)
	if plr:WaitForChild("PointMultiply").Value <= 1.1  then
	plr:WaitForChild("PointMultiply").Value += 2

	end

end)


Screenshot 2024-08-31 171817

Your script may be trying to infer the player from a part that is not actually part of the character model. For example, part.Parent could be another object that is not associated with a player.

1 Like

You aren’t checking to see if what you are sending is actually a character model. Check for a humanoid in their character’s model before defining your variables. Should look something like this:


local Players = game:GetService("Players")


script.Parent.Touched:Connect(function(part)
	local plr
	
	if part.Parent:FindFirstChild("Humanoid") then
		plr = Players:GetPlayerFromCharacter(part.Parent)
	else
		return warn("Player not found")
	end
	
	-- Continue code from here

end)
1 Like

I implemented the script and it works, thanks for the help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.