-
What do you want to achieve? I’m making a rolling system that lets the player roll different numbers when a TextButton is clicked.
-
What is the issue? The rolling system itself was working fine, but now the clicked event that does the rolling isn’t firing at all, even when the button is clicked.
-
What solutions have you tried so far? I’ve looked through devforum a bit to try to find answers, but none of them worked for me.
This is the script:
local player = game.Players.LocalPlayer
local character = player.CharacterAppearanceLoaded:Wait()
local head = character.Head
local RollUI = player:WaitForChild("PlayerGui").RollUI
local auraboxtemplate = script.Box
local ts = game:GetService("TweenService")
local AcceptButton = RollUI:WaitForChild("AcceptButton")
local DeclineButton = RollUI:WaitForChild("DeclineButton")
local crateSizeX = auraboxtemplate.AbsoluteSize.X
local crateGapX = 10
local crateTotalGapX = crateSizeX + crateGapX
local auraboxtemplate = script.Box
local ts = game:GetService("TweenService")
local CurrentAura = nil
local CurrentRNG = nil
local function CreateBoxes()
for i = 1, 135, 1 do
local newBox = auraboxtemplate:Clone()
newBox.Position = newBox.Position + UDim2.new(0, crateTotalGapX*(i-1), 0, 0)
newBox.Parent = RollUI.Frame
newBox.Name = "Box"
local ID = Instance.new("NumberValue")
ID.Parent = newBox
ID.Value = i
ID.Name = "ID"
end
end
RollUI.Parent.RollButton.Roll.MouseButton1Click:Connect(function()
print("Attempting roll")
CreateBoxes()
script.Parent.Roll.Interactable = false
local luck = 1
local base = 0.5
ts:Create(RollUI.BG, TweenInfo.new(1), {BackgroundTransparency = 0.5}):Play()
for i = 1, 135, 1 do
local co = coroutine.create(function()
repeat
task.wait(0.01)
until #RollUI.Frame:GetChildren() == 137
local number, name = game.ReplicatedStorage:WaitForChild("Remotes").RollFunction:InvokeServer(luck, base)
local box = nil
for i2, v in RollUI.Frame:GetChildren() do
if v.Name == "Box" then
if v:FindFirstChild("ID").Value == i then
box = v
local aura = Instance.new("StringValue")
aura.Parent = box
aura.Value = name
aura.Name = "Aura"
local RNG = Instance.new("NumberValue")
RNG.Parent = box
RNG.Value = number
RNG.Name = "RNG"
end
end
end
local copiedAuraTitle = nil
local copiedAuraRNG = nil
for i, v in game.ReplicatedStorage:WaitForChild("AuraTitles").NonSecret:GetChildren() do
if v.Name == name then
copiedAuraTitle = v.Aura
copiedAuraRNG = v.RNG
end
end
if copiedAuraTitle ~= nil and copiedAuraRNG ~= nil then
local newTitle = copiedAuraTitle:Clone()
local newRNG = copiedAuraRNG:Clone()
newTitle.Parent = box
newTitle.Text = name
newRNG.Parent = box
newRNG.Text = number.." rng"
else
local newTitle = game.ReplicatedStorage.AuraTitles.NonSecret.Basic.Aura:Clone()
local newRNG = game.ReplicatedStorage.AuraTitles.NonSecret.Basic.RNG:Clone()
newTitle.Parent = box
newTitle.Text = "unknown"
newRNG.Parent = box
newRNG.Text = number.." rng"
end
end)
coroutine.resume(co)
end
local selectedBox = nil
task.wait(1)
local SelectedAura = math.random(55, 110)
for _, v in RollUI.Frame:GetChildren() do
if v.Name == "Box" and v.ID.Value == SelectedAura then
selectedBox = v
break
end
end
local xNum = RollUI.Frame.CanvasPosition.X + selectedBox.AbsolutePosition.X - 545
local startPos = Vector2.new(xNum, 0)
RollUI.Frame.Visible = true
RollUI.Arrow.Visible = true
ts:Create(RollUI.Frame, TweenInfo.new(3, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {CanvasPosition = startPos}):Play()
task.wait(3)
selectedBox.BackgroundColor3 = Color3.fromRGB(148, 148, 148)
print("Completed Roll")
CurrentAura = selectedBox:FindFirstChild("Aura").Value
CurrentRNG = selectedBox:FindFirstChild("RNG").Value
end)
AcceptButton.MouseButton1Click:Connect(function()
game.ReplicatedStorage.Remotes.AcceptAura:Fire(CurrentAura, CurrentRNG)
end)
game.ReplicatedStorage.Remotes.AcceptAura.Event:Connect(function(aura, rng)
if not head:FindFirstChild("PlayerTitle") then
local title = game.ReplicatedStorage.PlayerTitle:Clone()
title.Parent = head
end
local playerTitle = head:FindFirstChild("PlayerTitle")
if playerTitle:FindFirstChild("Aura") then
playerTitle.Aura:Destroy()
playerTitle.RNG:Destroy()
end
if aura ~= nil then
for i, v in game.ReplicatedStorage.AuraTitles:GetChildren() do
if v.Name == aura then
local newAura = v:Clone()
local newRNG = v.Parent.RNG:Clone()
newAura.Parent = playerTitle
newRNG.Parent = player
end
end
end
CurrentAura = nil
CurrentRNG = nil
end)
By the event not firing, I mean it doesn’t even print the “Attempting Roll” at the very top of the function, which should fire the moment the button is clicked.
The script is a LocalScript in a ScreenGUI in StarterGUI.
If you have any questions or need more information, feel free to ask