Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Gun Shop GUI Help?

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

1

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"

0

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.

0

LocalPlayer is in game.Players

0

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.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.