So I made a time trial game recently with tools you can buy. But for some reason the tools count as the players hitbox and it can start and end the timer from far away. I worked on trying to solve this for around 2 hours and gave up. Anything I tried ended up breaking the sword tool in the game as well. Is there anyway to make it so the timer wont start if a players tool hits it?
Can you show the script that you use to end the timer?
Well seeing how the tool is part of the character, I suggest you go to the toolâs handle and disable its properties of: CanQuery and CanTouch.
As shrek said already, code would definitely be helpful to see.
But just want to make sure Iâm understanding this right. So you have a time trial where the timer is started by the player touching it, correct? In that case you would be using the .Touched event I imagine. The Touched event accepts parameters that provide the instance of the part that has touched another part to trigger the event.
game.Workspace.Part.Touched:Connect(function(partTouched) -- parameters go into those parentheses
if game.Players:GetPlayerFromCharacter(partTouched.Parent) then
print("Starting timer.")
else
print("Part is not the player.")
end
end)
This code would allow you to detect if the parent of the part touching your time trial is a playerâs character, so the parts of the playerâs body would trigger the trial, and any tools would not trigger it. rottendogDkRâs solution would work too, but would require you to disable those properties for every tool that could potentially touch the time trial. Hope this helps.
Okay i was afk ill send the code in a sec here
Here is the script
Okay i was afk ill send the code in a sec here
[/quote]
local par=script.Parent
local timer=par:WaitForChildâTimerâ
local timerlabel=timer:WaitForChildâTimeâ
local timertitle=timer:WaitForChildâTitleâ
local toggle=par:WaitForChildâToggleButtonâ
local SetTime = tick()
local RunService = game:GetService(âRunServiceâ)
â edit this like 0 digit = 1, 1 digit = 1.0, 2 digit = 1.00 3 digit = 1.000 etc
local RationalDigits = 3
function connectplrtouch(pt,func)
pt.Touched:Connect(function(t)
local c=game.Players.LocalPlayer.Character
if c and t:IsDescendantOf(c) then
func()
end
end)
end
local timer_active=false
local timer_time=0
function updatetogglebutton()
toggle.Position=UDim2.new(1,0,(timer.Visible and (string.len(timertitle.Text)>0 and .8 or .9) or 1),0)
toggle.Text=timer.Visible and âHide Timerâ or âShow Timerâ
end
updatetogglebutton()
toggle.MouseButton1Click:Connect(function()
timer.Visible=not timer.Visible
updatetogglebutton()
end)
local prev
for _,d in pairs(workspace:GetDescendants()) do
if d.Name==âTimer_Startv6â then
local name=(d:FindFirstChildâTitleâ and d.Title:IsAâStringValueâ and d.Title.Value) or ââ
connectplrtouch(d,function()
par.Enabled=true
if prev~=d then
SetTime = tick()
prev=d
end
timertitle.Text=name
timerlabel.TextColor3=Color3.new(1, 1, 1)
updatetogglebutton()
SetTime = tick()
timer_active=true
end)
end
if d.Name==âTimer_Pausev6â then
connectplrtouch(d,function()
timerlabel.TextColor3=Color3.new(0.282353, 0.282353, 0.282353)
if timer_active == true then
game.ReplicatedStorage.ApplyTimev6:FireServer(timerlabel.Text)
end
timer_active=false
end)
end
if d.Name==âTimer_Stopâ then
connectplrtouch(d,function()
par.Enabled=false
timerlabel.TextColor3=Color3.new(1,0,0)
timer_active=false
SetTime = tick()
end)
end
end
â[[
while wait(.1) do
if timer_active then
timer_time=timer_time+1
local txt=math.floor(timer_time)/10
local int,dec=math.modf(txt)
if dec<.09 then txt=(txtâŚâ.0â)end
timerlabel.Text=txt
end
end
]]
local Accuracy = 10^RationalDigits
function TimerFunc()
if timer_active then
local Div1 = math.abs(tick() - SetTime)
local CalculatedIncrement = math.round(Div1*Accuracy)/Accuracy
local Addons={}
for t=1,RationalDigits do
local i = t-1
local integer,predecimal = math.modf(CalculatedIncrement*(10^i))
local decimal = predecimal/(10^i)
if decimal == 0 then
Addons[t] = "0"
end
end
local NewText = tostring(CalculatedIncrement)
for i,v in pairs(Addons) do
NewText = NewText..v
end
timerlabel.Text=NewText
end
end
while true do
wait(.025)
TimerFunc()
end
i tried this before and it didnt work for some reason. I tried it again and it did maybe i forgot to click one last time thank you!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.