Hello, I am trying to do so the script runs when a player has been loaded into the server so it doesn’t say it can’t find things from players. I did so it doesn’t give me an error or anything, the script just doesn’t work. I can’t open up the shopGUI. Mostly the top line of the script you shoudl be looking at.
game.Players.PlayerAdded:Wait()
local player = game.Players.LocalPlayer
local ReplicateddStorage = game:GetService("ReplicatedStorage")
local shopButton = player.PlayerGui.ShopButton.Frame.TextButton
local shopGui = player.PlayerGui.ShopGui
shopButton.MouseButton1Click:Connect(function()
shopGui.Enabled = true
end)
local exitButton = player.PlayerGui.ShopGui.Frame.ExitButton
exitButton.MouseButton1Click:Connect(function()
shopGui.Enabled = false
end)
local stoneButton = player.PlayerGui.ShopGui.Frame.ScrollingFrame.StoneButton
local ironButton = player.PlayerGui.ShopGui.Frame.ScrollingFrame.IronButton
local diamondButton = player.PlayerGui.ShopGui.Frame.ScrollingFrame.DiamondButton
local stonePickaxe = game.ReplicatedStorage.BuyableItems.StonePickaxe
local ironPickaxe = game.ReplicatedStorage.BuyableItems.IronPickaxe
local diamondPickaxe = game.ReplicatedStorage.BuyableItems.DiamondPickaxe
local StoneValue = game.ReplicatedStorage.BuyableItems.StonePickaxe.StoneValue
stoneButton.MouseButton1Click:Connect(function()
if player.Backpack:FindFirstChild("StonePickaxe") or player.Character:FindFirstChild("StonePickaxe") then
stoneButton.TextLabel.Text = "UNEQUIPPED"
stoneButton.TextLabel.TextColor3 = Color3.new(170, 0, 0)
if player.Backpack:FindFirstChild("StonePickaxe") then
player.Backpack.StonePickaxe:Destroy()
elseif player.Character:FindFirstChild("StonePickaxe") then
player.Character.StonePickaxe:Destroy()
end
return
end
local stoneClone = stonePickaxe:Clone()
stoneClone.Name = "StonePickaxe"
stoneClone.Parent = player.Backpack
stoneButton.TextLabel.Text = "EQUIPPED"
stoneButton.TextLabel.TextColor3 = Color3.new(0, 255, 0)
end)
ironButton.MouseButton1Click:Connect(function()
if player.Backpack:FindFirstChild("IronPickaxe") or player.Character:FindFirstChild("IronPickaxe") then
end
end)
Use :WaitForChild("ChildName")
Instead of .ChildName
for example:
local player = game.Players.LocalPlayer
local ReplicateddStorage = game:GetService("ReplicatedStorage")
local shopButton = player:WaitForChild("PlayerGui"):WaitForChild("ShopButton"):WaitForChild("Frame"):WaitForChild("TextButton")
and remove the top line it’s not needed
EDIT: And replace all dots that connects parent and child with :WaitForChild
for example don’t replace game.Players.LocalPlayer with game.Players:WaitForChild("LocalPlayer") since “LocalPlayer” is not a child of “Players” or don’t replace shopGui.Enabled with shopGui:WaitForChild("Enabled") because same thing.
If yes, it’s mostly likely-done to-a-bug, if no activate it.
Or it’s maybe the game.Players.PlayerAdded:Wait() that disturbs everything.
So your code should look like this (Some unlisted thing will be here in the script)
task.wait(3)
local player = game.Players.LocalPlayer
local ReplicateddStorage = game:GetService("ReplicatedStorage")
local shopButton = player.PlayerGui.ShopButton.Frame.TextButton
local shopGui = player.PlayerGui.ShopGui
shopButton.MouseButton1Click:Connect(function()
shopGui.Enabled = true
end)
local exitButton = player.PlayerGui.ShopGui.Frame.ExitButton
exitButton.MouseButton1Click:Connect(function()
shopGui.Enabled = false
end)
local stoneButton = player.PlayerGui.ShopGui.Frame.ScrollingFrame.StoneButton
local ironButton = player.PlayerGui.ShopGui.Frame.ScrollingFrame.IronButton
local diamondButton = player.PlayerGui.ShopGui.Frame.ScrollingFrame.DiamondButton
local stonePickaxe = game.ReplicatedStorage.BuyableItems.StonePickaxe
local ironPickaxe = game.ReplicatedStorage.BuyableItems.IronPickaxe
local diamondPickaxe = game.ReplicatedStorage.BuyableItems.DiamondPickaxe
local StoneValue = game.ReplicatedStorage.BuyableItems.StonePickaxe.StoneValue
stoneButton.MouseButton1Click:Connect(function()
if player.Backpack:FindFirstChild("StonePickaxe") or player.Character:FindFirstChild("StonePickaxe") then
stoneButton.TextLabel.Text = "UNEQUIPPED"
stoneButton.TextLabel.TextColor3 = Color3.new(170, 0, 0)
if player.Backpack:FindFirstChild("StonePickaxe") then
player.Backpack.StonePickaxe:Destroy()
elseif player.Character:FindFirstChild("StonePickaxe") then
player.Character.StonePickaxe:Destroy()
end
return
end
local stoneClone = stonePickaxe:Clone()
stoneClone.Name = "StonePickaxe"
stoneClone.Parent = player.Backpack
stoneButton.TextLabel.Text = "EQUIPPED"
stoneButton.TextLabel.TextColor3 = Color3.new(0, 255, 0)
end)
ironButton.MouseButton1Click:Connect(function()
if player.Backpack:FindFirstChild("IronPickaxe") or player.Character:FindFirstChild("IronPickaxe") then
end
end)