So I'm working on an RPG and I'm trying to make a shop GUI like in RPG World or Slaying Simulator. I am a noob at scripting so if you know the answer, please tell me what I did wrong. Script: In the out
local buyer = game.Players.LocalPlayer script.Parent.MouseButton1Click:connect() if buyer.leaderstats.Gold.Value >= 100 and script.Parent.MouseButton1Click:connect() then game.ServerStorage.Folder.Sword:Clone().Parent = game.Players.LocalPlayer.Backpack end if buyer.leaderstats.Gold.Value <= 100 and script.Parent.MouseButton1Click:connect() then return end
To get the player, I'm assuming this is a GUI and since it gets cloned into the PlayerGui you can just go up in the hierarchy by using script.Parent
until you get the player object.
Let's look at your code:
-- local buyer = game.Players.LocalPlayer -- can't use this in a server script --assuming the hierarchical structure is ScreenGUI -> Frame -> Button -> Script local buyer = script.Parent.Parent.Parent.Parent.Parent -- getting the player script.Parent.MouseButton1Click:connect() if buyer.leaderstats.Gold.Value >= 100 then -- can't use events in an if statement game:GetService("ServerStorage").Folder.Sword:Clone().Parent = buyer.Backpack end end) -- Ending the mouse click event -- remove code below if buyer.leaderstats.Gold.Value <= 100 then -- Why is this here? And again, you can't use click events in an if statement return end -- this doesn't work