So i have this script:
game.Players.PlayerAdded:connect(function(player)
local Stats = Instance.new(“Model”, player)
Stats.Name = “leaderstats”
local Timer = Instance.new(“IntValue”, Stats)
Timer.Name = “Time”
Timer.Value = 0
while true do
wait(1)
Timer.Value = Timer.Value +1
end
end)
and i need help on making a script where after you die your timer resets to 0.
1 Like
Use the Humanoid.Died event:
player.CharacterAdded:Connect(function(character)
character.Humanoid.Died:Connect(function()
-- Do stuff that reset the stat
end)
end)
I gave you the exact script you asked for on a previous post by the way, as that previous post solves this posts question as well. Before making a new post you should read through your older posts
I believe this is what you were asking for
Throw this inside a script parented to the part you want touched
local part = script.Parent
local touchedplayers = {}
local debounce = false
-- you may remove the prints, kept them in to make it easier to understand the script
part.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
if debounce == false then -- this makes it so that the touched event doesn't run repeatedly
print('touched')
local player = ga…
.
Could i ask where to put this script?
Crrustyy
(boblox_man)
June 5, 2020, 2:31pm
#5
You would insert it like this:
game.Players.PlayerAdded:connect(function(player)
local Stats = Instance.new(“Model”, player)
Stats.Name = “leaderstats”
local Timer = Instance.new(“IntValue”, Stats)
Timer.Name = “Time”
Timer.Value = 0
while true do
wait(1)
Timer.Value = Timer.Value +1
end
player.CharacterAdded:Connect(function(character)
character.Humanoid.Died:Connect(function()
player.leaderstats.Time.Value = 0
end)
end)
end)
1 Like
Sorry about the many replies, i’m new to scripting.
About the code you told me to insert, do i need to add any other scrips to it? I tried that script and the time leaderboard didn’t show up.
For the script I gave you, that script goes in any part that you want touched to start the timer.
You should throw a script like this in serverscriptservice
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local timer = Instance.new("NumberValue",leaderstats)
timer.Name = "Timer"
end)
and this script below inside of a part
I believe this is what you were asking for
Throw this inside a script parented to the part you want touched
local part = script.Parent
local touchedplayers = {}
local debounce = false
-- you may remove the prints, kept them in to make it easier to understand the script
part.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
if debounce == false then -- this makes it so that the touched event doesn't run repeatedly
print('touched')
local player = ga…
Ahh thank you so much! It’s all good now