How to fix this?

So, I am trying to make it when a player touches the part it changes the text…and yeah I thought it’s so easy But apparently I am getting a error here:

local Viewer = game.Workspace.Viewer
local RS = game:GetService("ReplicatedStorage")
local ViewerEvent = RS.Viewer
local Disviewer = RS.DisViewer

Viewer.Touched:Connect(function(player)
		ViewerEvent:FireClient(player)
end)

Viewer.TouchEnded:Connect(function(player)
		Disviewer:FireClient(player)
end)

It shows FireClient: player argument must be a Player object, So yeah Idk how to fix that

To explain the code better, Whenver a player touches a part it fires a event called viewer that will change the text from something to something and when the player leave the part it will fire an event called disviewer that will revert the text back…

The thing touching the part is never player object, you have to get the player from the instance that touched the part:

Viewer.Touched:Connect(function(hit)
    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    if player then
        ViewerEvent:FireClient(player)
    end
end)
1 Like

For .Touched events, the first parameter is actually the part that touched/was touching it. Use :GetPlayerFromCharacter:

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local Viewer = workspace.Viewer
local ViewerEvent = ReplicatedStorage.Viewer
local Disviewer = ReplicatedStorage.DisViewer

--//Functions
Viewer.Touched:Connect(function(hit)
	local Player = Players:GetPlayerFromCharacter(hit.Parent)
	
	if Player then
		ViewerEvent:FireClient(Player)
	end
end)

Viewer.TouchEnded:Connect(function(hit)
	local Player = Players:GetPlayerFromCharacter(hit.Parent)

	if Player then
		Disviewer:FireClient(Player)
	end
end)
1 Like

Well totally forgot about that, Thank you so much! :slight_smile: