Heya I need help making a script where if a player touches a part their time triples to go up in speed
Here’s the leaderstat script
local DSS = require(game.ServerStorage.Modules.Datastores)
function onPlayerEntered(newPlayer)
local PlrStore = DSS:GetStore(newPlayer, "StatsStore", {})
--Blank table cuz we don't have a path
if not PlrStore then
repeat
PlrStore = DSS:GetStore(newPlayer, "StatsStore", {})
task.wait(0.25)
until PlrStore
end
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
stats.Parent = newPlayer
local score = Instance.new("IntValue",stats)
score.Name = "Time"
score.Value = PlrStore.Time
newPlayer.leaderstats.Time.Changed:connect(function()
if newPlayer.leaderstats.Time.Value >= 20 then
local tool = game.ReplicatedStorage.GreenLongsword
if not newPlayer.Backpack:FindFirstChild(tool.Name) then
local clone = tool:Clone()
clone.Parent = newPlayer.Backpack
end
end
if newPlayer.leaderstats.Time.Value == 70 then
local tool = game.ReplicatedStorage.BLongSword
if not newPlayer.Backpack:FindFirstChild(tool.Name) then
end
elseif newPlayer.leaderstats.Time.Value == 120 then
local tool = game.ReplicatedStorage.Darkheart
if not newPlayer.Backpack:FindFirstChild(tool.Name) then
end
end
if newPlayer.leaderstats.Time.Value == 200 then
local tool = game.ReplicatedStorage.Firebrand
if not newPlayer.Backpack:FindFirstChild(tool.Name) then
end
elseif newPlayer.leaderstats.Time.Value == 250 then
local tool = game.ReplicatedStorage.SwordoftheForsaken
if not newPlayer.Backpack:FindFirstChild(tool.Name) then
end
end
if newPlayer.leaderstats.Time.Value == 300 then
local tool = game.ReplicatedStorage.SwordoftheTyrant
if not newPlayer.Backpack:FindFirstChild(tool.Name) then
end
elseif newPlayer.leaderstats.Time.Value == 350 then
local tool = game.ReplicatedStorage.RedLongsword
if not newPlayer.Backpack:FindFirstChild(tool.Name) then
end
end
if newPlayer.leaderstats.Time.Value == 400 then
local tool = game.ReplicatedStorage.SandDancerScimitar
if not newPlayer.Backpack:FindFirstChild(tool.Name) then
end
elseif newPlayer.leaderstats.Time.Value == 450 then
local tool = game.ReplicatedStorage.FirebrandV2
if not newPlayer.Backpack:FindFirstChild(tool.Name) then
end
end
end)
newPlayer.CharacterAdded:Connect(function(char)
print("CharAdded")
local BillboardGui = game.ServerStorage.ClonedObjects.Example:Clone()
BillboardGui.Parent = char.Head
BillboardGui.Name = "Time"
BillboardGui.Time.Text = score.Value
end)
score.Parent = stats
stats.Parent = newPlayer
local function onValChanged(value)
--This is just for backwards compatibility because normally you would want to change the player stores then update leaderstats--
--but it wasn't like that so this updates the stats--
DSS:ChangeStore(newPlayer, "StatsStore", {value.Name}, value.Value)
end
score:GetPropertyChangedSignal("Value"):Connect(function()
onValChanged(score)
if newPlayer.Character then
if not newPlayer.Character.Head:FindFirstChild("Time") then
local BillboardGui = game.ServerStorage.ClonedObjects.Example:Clone()
BillboardGui.Parent = newPlayer.Character.Head
BillboardGui.Name = "Time"
BillboardGui.Time.Text = score.Value
end
newPlayer.Character.Head.Time.Time.Text = score.Value
end
end)
while true do
task.wait(0.85)
if not newPlayer.Character then return end
if not table.find(workspace:FindPartsInRegion3WithWhiteList(_G.SafeZone, {newPlayer.Character}), newPlayer.Character.HumanoidRootPart) then
newPlayer.leaderstats.Time.Value = newPlayer.leaderstats.Time.Value +1
end
end
end
game.Players.PlayerAdded:connect(onPlayerEntered)```