#Timer

94 messages · Page 1 of 1 (latest)

crystal valve
#

Hello. So I made a timer showing only when a player touches a specific part. However, when it counts, everybody can see it. How can I make sure that the player who touched the part is the ONLY ONE that views the timer?

Script located in ServerScriptService:

rs = game.ReplicatedStorage
TimeSeconds = rs.Seconds
TimeMinutes = rs.Minutes
TimeHours = rs.Hours
TimerParte = game.Workspace:WaitForChild("TimerPart")

local debounce = false

TimerParte.Touched:Connect(function()
    if debounce == false then
        debounce = true
        for i = 0, 86400, 1 do
    
            TimeSeconds.Value += 1
    
            if TimeSeconds.Value == 60 then
                TimeSeconds.Value = 0
                TimeMinutes.Value += 1
            end
    
            if TimeMinutes.Value == 60 then
                TimeMinutes.Value = 0
                TimeHours.Value += 1
            end
    
            wait(1)
        end
    end
end)

The local script for displaying the timer:

TimerGUI = script.Parent
rs = game.ReplicatedStorage
timerlabel = script.Parent:WaitForChild("TextLabel")
TimerParte = game.Workspace:WaitForChild("TimerPart")

TimerParte.Touched:Connect(function()
    rs.Seconds.Changed:Connect(function()
        timerlabel.Text = tostring(string.format("%0.2i", rs.Hours.Value) .. ":" .. string.format("%0.2i", rs.Minutes.Value) .. ":" .. string.format("%0.2i", rs.Seconds.Value))
    end)
end)
#

Any help would be appreciated, thanks!

umbral walrus
#

any gui can detect if its changing

#

so everybody can see it

#

you have to put the timer values inside the script

crystal valve
#

oh

#

lemme try that

umbral walrus
#

i mean inside the localscript

crystal valve
#

oh

umbral walrus
#

wait

crystal valve
#

and to make the gui only visible to the player who touched the part?

#

localscript yes

#

cuz the values have to be only for local player

umbral walrus
#

let me edit it rq

drowsy ruinBOT
#

studio** You are now Level 7! **studio

crystal valve
#

oh wait, I just have to put the script with the values inside StarterPlayerScript?

#

to make them local

umbral walrus
#

yeah that will work

crystal valve
#

ok i'll test

umbral walrus
#

but you have to make it a local script

#

a script inside a starterplayerscript wont work

crystal valve
#

ye$

spice salmon
#

Yo, what you need help with?

crystal valve
#

wait am testing and i will say if it works

spice salmon
#

I see you are trying to make a timer so you can use something like this:

crystal valve
#

mine works dw, i just want to display the timer to just the player who touches the part

#

and also makes the values local

spice salmon
crystal valve
#

so it always starts to 0

#

I'm a guy who respects the rule: If it works, don't touch

#

xd

#

alr so, i tested, it doesnt work$

#

i changed variables etc, but doesnt work

umbral walrus
crystal valve
#

ye

umbral walrus
#

can you show me

crystal valve
#
TimerGUI = script.Parent
timerlabel = script.Parent:WaitForChild("TextLabel")
TimerParte = game.Workspace:WaitForChild("TimerPart")

TimerParte.Touched:Connect(function()
    game.StarterPlayer.StarterPlayerScripts.TimerScript.Seconds.Changed:Connect(function()
        timerlabel.Text = tostring(string.format("%0.2i", game.StarterPlayer.StarterPlayerScripts.TimerScript.Hours.Value) .. ":" .. string.format("%0.2i", game.StarterPlayer.StarterPlayerScripts.TimerScript.Minutes.Value) .. ":" .. string.format("%0.2i", game.StarterPlayer.StarterPlayerScripts.TimerScript.Seconds.Value))
    end)
end)

Local script in GUI ^

umbral walrus
#

ye its wrong

#

lol

spice salmon
#

Oh god whats that

crystal valve
#

lmao

#

i couldnt use the variable btw in the string;format cuz it wont update after so

#

so have to do each time manually but its ok

umbral walrus
#

give me a sec

crystal valve
#

sure

umbral walrus
#

change game.StarterPlayer.StarterPlayerScripts with game.Players.LocalPlayer.PlayerScripts

spice salmon
#

Here, seconds, minutes, hours, days, weeks, months and years (I was bored one day)

drowsy ruinBOT
#

studio** You are now Level 31! **studio

spice salmon
#

!rank

drowsy ruinBOT
crystal valve
#

ok so the timer works now

#

why it failed before?

umbral walrus
#

game.StarterPlayer.StarterPlayerScripts this is wrong

crystal valve
#

well this is the path?

umbral walrus
#

you have to check the player scripts

spice salmon
#

Everything in StarterPlayer get cloned in player when join

crystal valve
#

ah

#

alr

#

and now, how to make

#

gui visible to the player who touched the part?

umbral walrus
#

TimerParte.Touched:Connect(function() local Player = game.Players.LocalPlayer Player.PlayerGUI.TimerCount.Visible = true

crystal valve
#

Enable works no?

umbral walrus
#

oh its a GUI

crystal valve
#

cuz the gui is "invisible" cuz there is not text

umbral walrus
#

mb

#

ye its enable instead of visible

crystal valve
#

btw, u made a mistake in writing

#

It's PlayerGui, not PlayerGUI

#

i got an error but its fixed now

#

now lemme test on 2 players

#

mhmmm doesnt <ork

umbral walrus
#

wait

#

TimerParte.Touched:Connect(function(player)
if player == game.Players.LocalPlayer then
game.Players.LocalPlayer.PlayerGui.TimerCount.Enable = true
end

#

oh wait nvm

#

hmm

#

TimerParte.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

if player == game.Players.LocalPlayer then
game.Players.LocalPlayer.PlayerGui.TimerCount.Enable = true
end

crystal valve
#

ok so now it works

#

but the timer isnt resetted

#

I think ik why

umbral walrus
#

just reset it

crystal valve
#

I will fix it later cuz I have smth to do, i leave the post open in case

umbral walrus
#

lol

crystal valve
#

@umbral walrus btw, thanks for help u, @spice salmon thx to u too 🦦

drowsy ruinBOT
#

studio** You are now Level 6! **studio

crystal valve
#

thx mee6 too

umbral walrus
#

im just bored, np

spice salmon
#

even tho I didnt help that much agony

crystal valve