Hello!
I want to fire an event if the player used a key card upon being touched. The "real" variable searches if it is a key card or not. Everything works fine except for the fire event which prints an error "FireClient: player argument must be a Player object" I tried for 30 minutes to fix this up but no idea came, if anyone can help me? Thank you!
script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) local real = hit:FindFirstChild("Real") if real then game.ReplicatedStorage.KeyCardDestroy:FireClient(player) -- Error end end)
ok, here we go again.. so im taking it the keycard has the "Real" value inside of it and that the keycard is a tool so
script.Parent.Touched:Connect(function(hit) local real = hit.Parent:FindFirstChild("Real")-- if real then local player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent)--you get the player from the character which is the tool parent, the handle of the tool being the child of tool so you need 2 .Parent to actually get to the player game.ReplicatedStorage.KeyCardDestroy:FireClient(player) end end)
This script might work, here is the script.
Script:
script.Parent.Touched:Connect(function(hit) local player = game.Players:FindFirstChild(hit.Parent) local real = hit.Parent:FindFirstChild("Real") if real then game.ReplicatedStorage.KeyCardDestroy:FireClient(player) end end)
If real's parent is in player then, use this script. It might work.
Script:
script.Parent.Touched:Connect(function(hit) local player = game.Players:FindFirstChild(hit.Parent) local real = player:FindFirstChild("Real") if real then game.ReplicatedStorage.KeyCardDestroy:FireClient(player) end end)
script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then --checks if player is found because sometimes the part touches the ground or something and returns nil instead of player if hit.Parent:IsAncestorOf("Real") then --checks if the character has a keycard equipped, I went with the IsAncestorOf function instead since I think it would be more consistent game.ReplicatedStorage.KeyCardDestroy:FireClient(player) end end end)
Let me know if there are any problems, I haven't tested this