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)

4 comments
Ummm, what? LocalPlayer is only for the person who clicked. To find someone who isn't you just do: "if not game.Players.LocalPlayer.Name == "fletchbestt" then"
I want the gun to be sold to the person who click's the guy buy button... But I can't seem to figure it out.
LocalPlayer is in game.Players
But say if i test in on studio, my player name is Player1... It will then say in the output that LocalPlayer does not exist in Players.