Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Gun Shop GUI Help?

Asked by
Cuvette 246 Moderation Voter
9 years ago

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)
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" EzraNehemiah_TF2 3552 — 9y
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. Cuvette 246 — 9y
0
LocalPlayer is in game.Players EzraNehemiah_TF2 3552 — 9y
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. Cuvette 246 — 9y

1 answer

Log in to vote
0
Answered by
Cuvette 246 Moderation Voter
9 years ago

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)
Ad

Answer this question