When the player comes near, it opens a proximity prompt (with a custom GUI) and when it’s activated, the GUI opens. The GUI is a dialogue GUI where players can chat, if they click on the button that says “ok”, the button gives them tools, but if they click “no”, the button in a different script will close the GUI.
debounce = true
script.Parent.Triggered:Connect(function(Plr)
print(Plr)
-- checks if the script wasn't already activated
if debounce then
debounce = false
-- Activates the NPC dialogue
game.ReplicatedStorage:WaitForChild("Skating Gui"):Clone().Parent = Plr.PlayerGui
local gui = Plr.PlayerGui:FindFirstChild("Skating Gui")
local text = gui.Frame.ImageLabel.TextLabel
gui.Frame.Position = UDim2.new(0.318, 0, 2, 0)
gui.Frame:TweenPosition(UDim2.new(0.298, 0, 0.668, 0))
gui.Frame.Visible = true
-- typewriting effect for text
local function typewrite(object, speech)
for i = 1, #speech, 1 do
object.Text = string.sub(speech,1,i)
wait()
end
end
typewrite(text,"Hello! Welcome to Oceanview Skating! I am the person you go to for your tools!")
wait(1)
typewrite(text,"To get more tools available, you can attend classes and level up!")
wait(1)
typewrite(text,"It looks like you are the "..Plr.Levels.Value.." level. Would you like your tools?")
wait(1)
-- Open the skating gui
gui.Frame.ImageLabel.TextLabel.Ok.MouseButton1Down:Connect(function(mouse)
print("Button works")
local level = Plr.Levels.Value
local gui = Plr.PlayerGui:FindFirstChild("Skating Gui")
gui.Frame:TweenPosition(UDim2.new(0.318, 0, 2, 0))
wait(1)
local Backpack = Plr.Backpack
if #Backpack:GetChildren() <= 0 then
local tools = game.ReplicatedStorage.SkatingMoves:FindFirstChild(level):GetChildren()
for i, tool in pairs (tools) do
tool:Clone().Parent = Plr.Backpack
end
else
Plr.Backpack:ClearAllChildren()
local tools = game.ReplicatedStorage.SkatingMoves:FindFirstChild(level):GetChildren()
for i, tool in pairs (tools) do
tool:Clone().Parent = Plr.Backpack
end
end
gui:Destroy()
debounce = true
end)
end
end)
~~~
1 Like
Could you send a video showing how it “breaks”?
Are you getting any errors? If so, where are they? There isn’t a lot to go off from this (at least while I cannot access a device with Roblox Studio, I am currently on mobile).
It’s actually quite difficult to replicate because I don’t really know why it’s breaking, it’s becoming unusable. There aren’t any errors that come from this, aside from the script being unable to find the player’s main GUI after a while, and if I click the script it still prints out my username but it doesn’t do anything else.
Is your script getting caught on the :WaitForChild(), on line 7?
I don’t think so, it usually works, but after some gameplay, it breaks.
Alright, can you post a picture of your explorer tab, so I can try to replicate your problem and find a solution?
Since my game has a lot of parts, I took pics of only the significant ones
I believe I know what is happening, but really quick just run this to comfirm it:
debounce = true
script.Parent.Triggered:Connect(function(Plr)
print(Plr)
-- checks if the script wasn't already activated
if debounce then
debounce = false
-- Activates the NPC dialogue
game.ReplicatedStorage:WaitForChild("Skating Gui"):Clone().Parent = Plr.PlayerGui
local gui = Plr.PlayerGui:FindFirstChild("Skating Gui")
local text = gui.Frame.ImageLabel.TextLabel
gui.Frame.Position = UDim2.new(0.318, 0, 2, 0)
gui.Frame:TweenPosition(UDim2.new(0.298, 0, 0.668, 0))
gui.Frame.Visible = true
-- typewriting effect for text
local function typewrite(object, speech)
for i = 1, #speech, 1 do
object.Text = string.sub(speech,1,i)
wait()
end
end
typewrite(text,"Hello! Welcome to Oceanview Skating! I am the person you go to for your tools!")
wait(1)
typewrite(text,"To get more tools available, you can attend classes and level up!")
wait(1)
typewrite(text,"It looks like you are the "..Plr.Levels.Value.." level. Would you like your tools?")
wait(1)
-- Open the skating gui
gui.Frame.ImageLabel.TextLabel.Ok.MouseButton1Down:Connect(function(mouse)
print("Button works")
local level = Plr.Levels.Value
local gui = Plr.PlayerGui:FindFirstChild("Skating Gui")
gui.Frame:TweenPosition(UDim2.new(0.318, 0, 2, 0))
wait(1)
local Backpack = Plr.Backpack
if #Backpack:GetChildren() <= 0 then
local tools = game.ReplicatedStorage.SkatingMoves:FindFirstChild(level):GetChildren()
for i, tool in pairs (tools) do
tool:Clone().Parent = Plr.Backpack
end
else
Plr.Backpack:ClearAllChildren()
local tools = game.ReplicatedStorage.SkatingMoves:FindFirstChild(level):GetChildren()
for i, tool in pairs (tools) do
tool:Clone().Parent = Plr.Backpack
end
end
gui:Destroy()
end)
debounce = true
end
end)
It still seems to be breaking, but I think I know why it’s breaking now. It breaks every time someone presses the “Bye” button
This is the script for the “bye” button"
script.Parent.MouseButton1Down:Connect(function()
local gui = script.Parent.Parent.Parent.Parent.Parent
gui.Frame:TweenPosition(UDim2.new(0.318, 0, 2, 0))
wait(1)
gui:Destroy()
end)
Hmmm… Could you post the code for that? I thought maybe it was because you have a deBounce and you just weren’t resetting it back to true at the end of your code.
Edit: Never mind the code part.
Is this a part of the same script?
Nope, it’s apart of a different script, this one is inside of the GUI button
There is your problem, you have a deBounce in your first script that prevents you from opening the Ui again once it is opened, until you select ok
, but if you select bye
you are not resetting the deBounce. I would merge the two scripts together so you can reset the deBounce when the player selects bye
or, if it is extremely important for them to be two different scripts, then, instead of the deBounce, make it check whether or not the player has the Ui open or not.
1 Like