Hello, could someone help me debug this script?
-
What do you want to achieve? These scripts are part of a point giver script, where the player has to click a button in time to get points. This is triggered by stepping on a part which is destroyed after touch.
-
What is the issue? The script is not running to the place where the RemoteEvent fires (fired2 not printing), but there are no errors. The points are calculated correctly (printing correctly).
-
What solutions have you tried so far? This new framework is mostly a fix for another issue (variables not resetting when script.Enabled is set to false(?)).
LocalScript for pressing the button:
math.randomseed(os.time())
local player = game.Players.LocalPlayer
local pl_gui = player.PlayerGui.MinigameGUI
local button = pl_gui.ImageButton
local label = pl_gui.TimeLabel
local storage = game.ReplicatedStorage
local db = false
button.MouseButton1Click:Connect(function()
if db == false then
db = true
print("You clicked with ".. tostring(ticktimer) .." seconds left!")
local savedtimer = timer
local savedticktimer = ticktimer
score = math.round((savedtimer / 10 - savedticktimer) * 10)
print(score)
end
wait(1)
print("firing...")
storage.GivePoints:FireServer(score)
pl_gui.Enabled = false
script.Enabled = false
end)
while true do
timer = Random.new():NextInteger(30, 50)
ticktimer = timer / 10
wait(1)
for i = 1, timer do
if i <= timer then
-- print(tostring(i))
wait(0.1)
ticktimer = math.round((ticktimer - 0.1) * 10) / 10
-- print(tostring(ticktimer))
label.Text = "Time: " ..tostring(ticktimer)
end
end
pl_gui.Enabled = false
script.Enabled = false
end
ServerScript that fires the event:
local activator = script.Parent
local db = false
local db_time = 8
local storage = game.ReplicatedStorage
activator.Touched:Connect(function(hit)
print("fired!")
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
print(tostring(db))
if player and db == false then
db = true
wait(1)
storage.OpenScript:FireClient(player)
script.Parent.Parent:Destroy()
wait(db_time)
db = false
end
end)
Test model hierarchy:
Actual model(s)’ hierarchy:
Thanks for reading this post!