Here is a script I have to purchase a 'Pistol' through my GUI. Everything works and the player can purchase a gun... Aslong as their name is fletchbestt. I have been searching for quite a while trying to find a way of it searching for the local player that has clicked the purchase gun button and not just a specific player that I have input. Are there any inbuilt functions in Roblox that I could use?
Thanks in advance for any help people give.
-- Fletchbestt's GUI Shop - Pistol playerbuy = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent price = 10 script.Parent.MouseButton1Click:connect(function() local v = playerbuy.fletchbestt.LocalPlayer:FindFirstChild("leaderstats").Cash if v.Value >= price then game.Lighting.Pistol:clone().Parent = playerbuy.Players.fletchbestt:FindFirstChild("Backpack") v.Value = v.Value - price print ('Pistol Purchased') else print ('You cannot afford this') end end)
I've managed to fix it after hours of searching, here is what my code now looks like. Thanks for your help, it was the LocalPlayer issue that you mentioned.
print ('Working Shop!') local player = game.Players.LocalPlayer print (player:GetFullName()) price = 50 script.Parent.MouseButton1Click:connect(function() local v = player:findFirstChild("leaderstats").Cash if v.Value >= price then game.Lighting.Pistol:clone().Parent = player:findFirstChild("Backpack") v.Value = v.Value - price print ('Pistol Purchased') else print ('You cannot afford this') end end)