Hello. I want to make a simple delivery script where you get a GUI from a box, it rolls a number from 1-3 and you have to deliver the box to the dropoff point with the corresponding number.
The problem is that nothing happens when I enter the dropoff point, regardless of if it’s the correct number or not.
Script 1 [how you get the box\gui]
script.Parent.Part.ProximityPrompt.Triggered:Connect(function(plr)
if plr.TeamColor == BrickColor.new("Dark indigo") then
local gui = script.BoxUI:Clone()
local randomnumber = math.random(0,3)
if randomnumber == 1 then
gui.Parent = plr.PlayerGui
gui.TextLabel.Text = "Deliver the package to the Corner Store"
gui.Value.Value += 1
elseif randomnumber == 2 then
gui.Parent = plr.PlayerGui
gui.TextLabel.Text = "Deliver the package to Silber Auto"
gui.Value.Value += 2
elseif randomnumber == 3 then
gui.Parent = plr.PlayerGui
gui.TextLabel.Text = "Deliver the package to Resources & Wildlife"
gui.Value.Value += 3
end
end
end)
Script 2 [dropoff]
script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
local plrgui = plr:FindFirstChild("PlayerGui")
if plrgui:FindFirstChild("BoxUI") then
if plrgui.BoxUI.Value.Value == "3" then
plrgui:FindFirstChild("BoxUI"):Destroy()
local c = script.CompleteBoxUI:Clone()
c.Parent = plrgui
wait(3)
c:Destroy()
end
end
end)
In your script 1 the random number can be ‘0’. You have to change it to math.random(1,3)
since it also includes the ‘0’. Maybe you got a 0 and then it does nothing because you don’t have a if statement for it.
1 Like
math.random(0,3) works fine, that isnt the problem
But it is? You only have if statements for the numbers 1,2,3 not 0. And it is possible for it to be 0. If you’re very unlucky it has chosen 0 every time you have tested it. If you’re sure that has not happened then what kind of script is the second script?
They’re both server scripts and I’m sure it has never given me a 0, I’ve checked
I strongly advise you to make it math.random(1,3)
if not you can possibly get ‘0’ and then it will do nothing so you have to click until you get something other than 0.
Well other than that then I’m not sure what could be wrong. Make sure the player is on the right team. Also if the first script works and the second does not try printing at different times in the second script so you know where it stops. Other than the placement of your code in the second script. The spaces between are not really put correctly. Try making it like:
script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
local plrgui = plr:FindFirstChild("PlayerGui")
if plrgui:FindFirstChild("BoxUI") then
if plrgui.BoxUI.Value.Value == "3" then
plrgui:FindFirstChild("BoxUI"):Destroy()
local c = script.CompleteBoxUI:Clone()
c.Parent = plrgui
wait(3)
c:Destroy()
end
end
end)
Found the bug. It wasn’t supposed to be
Value == “1” but instead Value == 1
Thanks for your help though!