How would I make it to wear if a player touches a part their time goes up 3x

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)```

Alright, you should simply used a Touched function, :GetPlayerFromCharacter() and some simple multiplication. Also, add a debounce as to make it not be spammed.

local part = --part
local debounce = false

part.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr and not debounce then
		debounce = true
		plr.leaderstats.Time.Value *= 3
		task.wait(1)
		debounce = false
	end
end)

So do I put this in a part or?

You don’t have to put it inside of a part, but if you do, simply make part reference the script’s parent.

local part = script.Parent

Heya it adds time it doesnt make the time speed up by 3x it just triples the current time

Oh, I completely misunderstood what you meant. I believe something like this should work?

part.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		local timel = plr.leaderstats.Time --timel because time is a variable
		local val = timel.Value
		local conn

		local function multi()
			conn = timel:GetPropertyChangedSignal("Value"):Connect(function()
				local change = timel.Value - val
				conn:Disconnect()
				timel.Value += change*2
				multi()
			end)
		end
	end
end)

Uh what do I put it in?

I don’t understand where to put it in

You put it in the exact same way as you did before. Also, I forgot the part variable, so don’t forget to put that in too.