Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a brick that times you on how long you are on it?

I'm trying to make a brick that will time you how long to stand on it, but I don't know where to start.

1 comment

0

OMG GREAT QUESTION, I NEVER THOUGHT OF THAT

2 answers

you could detect when touched (and even put a toggle so you can only do one player at a time) and start timing from there. (time is some function or somehting i dont and never cared to know about, so put change time variable.

timeA = 0
can = true

script.Parent.Touched:Connect(function(hit)
if can == true then
can = false
repeat timeA = timeA + 1 until script.Parent.TouchEnded do script.Parent.someGUI.Textlabel.Text = timeA
wait(5)--so player can see time or whatever you need to do with time
timeA = 0
can = true
end
end)

Use Touched and TouchEnded

local tim = 0
local tab = {}

script.Parent.Touched:Connect(function(t)
	if game.Players:GetPlayerFromCharacter(t) and not tab[t.Parent.Name] then
		tab[t.Parent.Name] = tick()
	end
end)

script.Parent.TouchEnded:Connect(function(t)
	if game.Players:GetPlayerFromCharacter(t) and tab[t.Parent.Name] then
		print("Player "..t.Parent.Name.." Time On Brick Was "..math.floor(tick()-tab[t.Parent.Name]))
		tab[t.Parent.Name] = nil -- cleanup
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.