That’s not how the TouchEnded event works. It gives one parameter: the part that touched it. You are trying to cast it to a string and then passing it to FireClient, which needs a Player object.
local players = game:GetService("Players")
local rStorage = game:GetService("ReplicatedStorage")
local event = --[[path to event here]]
local part = --[[path to part here]]
local function processTouch(hit)
local player = players:GetPlayerFromCharacter(hit.Parent)
if player then
event:FireClient(player)
end
end
part.TouchEnded:Connect(processTouch)
heres an example of how to use the TouchEnded event, I haven’t tested it yet
local part = script.Parent
local event = game.ReplicatedStorage.TutorialNotif
part.TouchEnded:Connect(function(hit) — changed “plr” to hit"
if hit.Parent:FindFirstChild(“Humanoid”) then
local player = game:GetService(“Players”):GetPlayerFromCharacter(hit.Parent)
event:FireClient(player) — has to be a player object
end
end)
in this case you should add a debounce, here’s a basic example
local part = script.Parent
local event = game.ReplicatedStorage.TutorialNotif
DB = false
part.TouchEnded:Connect(function(hit) — changed “plr” to hit"
if hit.Parent:FindFirstChild(“Humanoid”) and not DB then
DB = true
local player = game:GetService(“Players”):GetPlayerFromCharacter(hit.Parent)
event:FireClient(player) — has to be a player object
wait(1)
DB = false
end
end)
One last thing. The current debouncing method is basic and doesn’t account for individual players. When someone receives a notification, other players won’t be able to receive any notifications if someone has already, this will last until the debounce period ends. You should consider a debouncing method that takes into account each player. That way, each player can receive notifications separately.
Here is a better example and better explanation, I haven’t tested it but it should work:
local part = script.Parent
local event = game.ReplicatedStorage.TutorialNotif
– Table to keep track of debounce states for each player
local playerDebounces = {}
part.TouchEnded:Connect(function(hit)
– Check if the touching object is a character with a Humanoid and a player associated with it
if hit.Parent:FindFirstChild(“Humanoid”) then
local player = game:GetService(“Players”):GetPlayerFromCharacter(hit.Parent)
– Check if the player exists and is not currently debounced
if player and not playerDebounces[player.UserId] then
– Set the player’s debounce state to true
playerDebounces[player.UserId] = true
– Fire the event for that specific player
event:FireClient(player)
– Wait for a second before allowing the player to trigger the event again
wait(1)
– Reset the player’s debounce state
playerDebounces[player.UserId] = false
end
end
end)
local part = script.Parent
local players = game:GetService("Players")
local debounces = {}
local function onTouched(touchedPart)
local model = touchedPart:FindFirstAncestorOfClass("Model")
if not model then return end
local player = players:GetPlayerFromCharacter(model)
if (not player) or debounces[player] then return end
debounces[player] = true
task.wait(1) --change cool down length
debounces[player] = nil
end
part.Touched:Connect(onTouched)