I am trying to make a script which activates leaderstats on touch, but I keep on getting this error.
20:36:18.284 - Touched is not a valid member of Workspace 20:36:18.285 - Stack Begin 20:36:18.285 - Script 'Workspace.Script', Line 10 20:36:18.286 - Stack End
and this is my full script
function onTouched(part)
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Model", player)
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local money = Instance.new("IntValue") --We create a new IntValue
money.Name = "Stage" --this is the name you want the leader-stat to be when it shows up in-game.
money.Value = 50 --this is the value of money the new player starts out with. To change this, you can add some more code (shown later)
money.Parent = leaderstats -- Set the money object as a child of the leaderstats object.
local Timer = Instance.new("IntValue") --We create a new IntValue
Timer.Name = "Time" --this is the name you want the leader-stat to be when it shows up in-game.
Timer.Value = 0 --this is the value of money the new player starts out with. To change this, you can add some more code (shown later)
Timer.Parent = leaderstats -- Set the money object as a child of the leaderstats object.
while true do
wait(1)
Timer.Value = Timer.Value +1
local Deaths = Instance.new("IntValue") --We create a new IntValue
Deaths.Name = "Deaths" --this is the name you want the leader-stat to be when it shows up in-game.
Deaths.Value = 25 --this is the value of money the new player starts out with. To change this, you can add some more code (shown later)
Deaths.Parent = leaderstats -- Set the money object as a child of the leaderstats object.
player.CharacterAdded:connect(function(Character)
Character:WaitForChild("Humanoid").Died:connect(function()
Deaths.Value = Deaths.Value - 1
if Deaths.Value == 0 then
local msg = Instance.new("Message")
msg.Parent = game.Workspace
msg.Text = "GAME OVER Try again"--this is an example
wait(2.5) -- change this time to however many seconds you want the message to remain
msg:remove()
end
script.Parent.Touched:connect(onTouched)
end)
end)
end
end)
end
I am making a special kind of obby.
Help is appreciated

4 comments
i need the touch the touch event because i am making people race, so it is timed
You could use any event, just change PlayerAdded
I am new to scripting so could you please explain on a script. Thank you sooo much. Btw Your script worked better than i thought it would.
I tried what you said, i replaced the 1st line (PlayerAdded) with (Touched) and it gave me an error " Touched is not valid member of Players