I sometimes get this error: FireClient: player argument must be a player object and it's just sometimes that this happens, and it doesn't detect it was a player even tho it was. This fires the event: (server script)
local brick = script.Parent local brickTouchedEvent = game.ReplicatedStorage.Events.BrickTouched local debounce = false brick.Touched:Connect(function(hit) if not debounce then debounce = true local player = game.Players:GetPlayerFromCharacter(hit.Parent) brickTouchedEvent:FireClient(player) print(player.Name.."opened the gui!") wait(4) debounce = false end end)
And this sets what the event does: (local script)
brickTouchedEvent.OnClientEvent:Connect(function() gui.Enabled = true gui.Frame.bmw.GoLeftShowHOON.Visible = true gui.Frame.bmw.GoRightShowPOR.Visible = true gui.Frame.Close.Visible = true camera.CameraType = Enum.CameraType.Scriptable camera.CFrame = workspace.Cameras.BMWPart.CFrame char.Humanoid.WalkSpeed = 0 script.Disabled = true end)
You need to have a check that makes sure the part that it has touched is actually the player.
Do something like this
local Event = game.ReplicatedStorage.Event local Part = workspace.Part Part.Touched:Connect(function(hit) if game.Players:FindFirstChild(hit.Parent.Name) then local Player = game.Players:GetPlayerFromCharacter(hit.Parent) Event:FireClient(Player) end end)
You said that something touched the brick. You can check if it's ClassName is Humanoid then run a function else just do nothing. Here's how you do it :
function onTouch(hit) if hit.Parent:IsA("Humanoid") then print("A player touched the brick.") else print("It was not a player who touched the brick.") end script.Parent.Touched:Connect(onTouch)
If you still have questions ask me!
When you are doing FireClient
, you need to pass along a "player object" to specify what player should be targeted. I found this very complicated myself, so I basically sent the information to every client (so I wouldn't have to put in a player object), along with the targeted player name variable, playerName. In a client script, I said that if the local player's name was equal to that of the variable playerName, then it would run a function to kill the player.
-------SERVER SCRIPT-------
targetPlayer.FireAllClients(playerTargeted)--targetPlayer is the name of the `remoteEvent`, and you would define `playerTargeted` as the player you wanted to be given the info.
-------CLIENT SCRIPT-------
function killPlayer() --[[ Insert the code to kill the player. --]] end targetPlayer.OnClientEvent:Connect(killPlayer)
I hope this helped, and happy coding!