What is "Player argument must be a player object"?

I have a script that when you touch a part, its supposed to destroy a UI. I have a RemoteEvent, and all my code seems to work fine, but it still doesn’t work. I’ve tried look at the developer forums, and I tried code someone else had wrote and modified it a little to fit my needs, but it still gave me the same error.

Code:

Server, (Located inside of a part thats in workspace)

local rs = game:GetService("ReplicatedStorage")
local re = rs:WaitForChild("RemoteEvent")
local part = script.Parent

part.Touched:Connect(function(Player)
	re:FireClient(Player)
end)

Local, (In a textbutton within a ScreenGui that is inside of StarterGui)

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
	script.Parent:Destroy()
end)
1 Like

Because your specifying the players character, not the actual player.

game.Players:GetPlayerFromCharacter(player.Parent)

--so,
local rs = game:GetService("ReplicatedStorage")
local re = rs:WaitForChild("RemoteEvent")
local part = script.Parent

part.Touched:Connect(function(Player)
re:FireClient(game.Players:GetPlayerFromCharacter(Player.Parent))
end)
3 Likes

What you defined by “Player” (in the Touched function) is not the player object. It’s what touched the part (so one of limbs of the player’s character)

As @geometricalC2123 did, you can simply use Player.Parent to find the character of the player and use GetPlayerFromCharacter() to find the player.

Here is what I’d do:

local rs = game:GetService("ReplicatedStorage")
local re = rs:WaitForChild("RemoteEvent")
local part = script.Parent

part.Touched:Connect(function(hit)
 	if hit.Parent:FindFirstChild("Humanoid") then
 		local character = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		re:FireClient(player)
    end
end)

You might wanna add a debounce too.

3 Likes

It works good, it triggers when touched and destroys the Gui, like I want it to! I still get the same error though. Perhaps its something wrong with Roblox?

1 Like

Can you show us the error please? Like, the output you got.

1 Like

No, it’s because your accessory is touching it, so use @heisllan solution.

1 Like

Yeah, the error was with your script. Both scripts work good though, but if you don’t want an error, use @heisIlan’s script

1 Like

Just check if the parent is an accessory, if it is do script.Parent.Parent

1 Like

I need help with this script (i’ve edited it so that it only works if leaderstats is above a certain value

Code: (Runs on the server)

local rs = game:GetService("ReplicatedStorage")
local re = rs:WaitForChild("RemoteEvent")
local part = script.Parent

part.Touched:Connect(function(hit)
	local character = hit.Parent
	local player = game.Players:GetPlayerFromCharacter(character)
	if player.leaderstats.Splits.Value < 15 then
		if hit.Parent:FindFirstChild("Humanoid") then
			re:FireClient(player)
		end
	end
end)

--player.leaderstats.Splits.Value < 15
--hit.Parent:FindFirstChild("Humanoid")

I get this error:

Are you sure there’s leaderstats exists? If do try this.

player:FindFirstChildWhichIsA("Folder").Splits.Value < 15 then

You could add a :WaitForChild(“leaderstats”).

Now I’m getting this error.