So I have an onTouch Script and if someone touches it the event will happen for all users. How do I make it so that only the player who touched the part with the onTouch script can see the event. The script I use for onTouch Events:
local function onTouch(hit) [Code goes here] end script.Parent.Touched:Connect(onTouch)
Edit: Referring to your comment, you forgot to put an "end" to close the function and you would also have to check if it's a player
function onTouch(hit) if hit.Parent:FindFirstChild("Humanoid)" then --code here end end script.Parent.Touched:Connect(onTouch)
If you mean all players (game.Players) then
function onTouch(hit) if hit.Parent:FindFirstChild("Humanoid") then --checks if it's a real player for i,v in pairs(game.Players:GetPlayers()) do --goes through the list of game.Players --code here (use v for the players in game.Players) end end end script.Parent.Touched:Connect(onTouch)
But if you mean all of the character's players then
function onTouch(hit) if hit.Parent:FindFirstChild("Humanoid") then --checks if it's a real player for i,v in pairs(game.Players:GetPlayers()) do --goes through the list of game.Players v.Character -- add code here --example: v.Character.Humanoid.Health = 0 end end end script.Parent.Touched:Connect(onTouch)