So I am working on a Dice Rolling script, essentially you press a TextButton and it will run the function.
The function is the dice rolling script, and uses a BillBoard gui in ReplicatedFirst, adds a random number in there, clones it and then places it in the Character's HumanoidRootPart
But I keep getting an error Attempting to index nil with Character
This is also a LocalScript, here it is The problem is on line 16
local rep = game:GetService("ReplicatedFirst")
local gui = rep:WaitForChild("d20gui")
local db = game:GetService("Debris")
local OpenMenu = script.Parent
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
OpenMenu.MouseButton1Click:Connect(function(p)
local toomany = false
local count = 0
math.randomseed(tick())
local charch = p.Character:GetChildren()
local existingd20tabs = {}
for i, v in pairs(charch) do
if v.Name == "d20gui" then
count = count + 1
table.insert(existingd20tabs, v)
end
end
if count < 5 then
for i, v in pairs(existingd20tabs) do
v.StudsOffsetWorldSpace = v.StudsOffsetWorldSpace + Vector3.new(0, 2, 0)
end
local pgui = gui:Clone()
pgui.Parent = p.Character
pgui.Adornee = p.Character.HumanoidRootPart
local text = pgui:WaitForChild("Frame"):WaitForChild("number")
text.Text = math.random(1, 20)
for i = 1, 17 do
local modifier = math.ceil(i / 5)
local newnumber = math.random(1, 20)
--print(0.05 * modifier)
wait(0.05 * modifier)
text.Text = newnumber
end
wait(5)
pgui:Destroy()
end
end
)

3 comments
Could you put your code inside a code block in this question? Edit the question and use the "Lua" icon to create a code block, and put the code between the ~ lines.
well where is "p" defined
There we go I added the lua block Im sorry about that