Hello! I was making a script that goes out to multiple clients and when I clone something then fire a server it says attempt to index nil with text.
local script:
game.ReplicatedStorage.FactoriesFrame:Clone().Parent = script.Parent
for i, v in pairs(script.Parent.FactoriesFrame:GetChildren()) do
if v:IsA("ImageLabel") then
v.Button.Text = v.Name.." Factory - $"..v.Price.Value
v.Button.MouseEnter:Connect(function()
v.ImageColor3 = Color3.new(0.701961, 0.701961, 0.701961)
end)
v.Button.MouseLeave:Connect(function()
v.ImageColor3 = Color3.new(0.298039, 0.298039, 0.298039)
end)
v.Button.MouseButton1Click:Connect(function()
local Val = v.Price.Value
local Button = v.Button
local Name = v.Name
game.ReplicatedStorage.Factories:FireServer(Val, Button, Name)
end)
end
end
EventScript:
Factory.OnServerEvent:Connect(function(Player, Val, Button, Name)
local char = Player.Character
local ProfileCacher = require(game.ServerScriptService.ProfileCacher)
local Profile = ProfileCacher[Player]
local Data = game.ServerStorage.PlayerData:FindFirstChild(Player.Name)
if Data.Role.Value == "King" then
local success, err = pcall(function()
if Profile.Data.Cash >= Val then
else
Button.Text = "Not Enough Cash!"
wait(1)
Button.Text = Name.." Factory - $"..Val
end
end)
if not success then print(err) end
end
end)