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

Gun shop script doesn't work?

Asked by
lucas4114 607 Moderation Voter
9 years ago

So, I'm trying to make a gun shop gui on my game and it doesn't work and the output doesn't say anything and idk what to do... (It's in a local script)

function BuyGun()
    local Clicked = game.Players.LocalPlayer
    local Player = game.Players:WaitForChild(Clicked)
    if Player.leaderstats.Points.Value >= 10 then
        Player.leaderstats.Points.Value = Player.leaderstats.Points.Value - 10
        local Gun = game.ServerStorage.Pistol:Clone()
        Gun.Parent = Player.Backpack
    end
end

script.Parent.MouseButton1Click:connect(BuyGun)

1 answer

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
9 years ago

Yo Prob Ese

You tried to get the Player using FindFirstChild() incorrectly. You also had no need to use it like that. When you use it, you need to use a string of the objects name you're getting.


Fix

function BuyGun()
    local Player = game.Players.LocalPlayer
    if Player.leaderstats.Points.Value >= 10 then
        Player.leaderstats.Points.Value = Player.leaderstats.Points.Value - 10
        local Gun = game.ServerStorage.Pistol:Clone()
        Gun.Parent = Player.Backpack
    end
end

script.Parent.MouseButton1Click:connect(BuyGun)

Try it now


Anyways, hope this helped, if you have any further questions/problems, please leave a comment below :P

-Dyler3

0
Hmm, thanks, I used FindFirstChild because the wiki said LocalPlayer was read only, but I guess the wiki was wrong then. XD lucas4114 607 — 9y
0
Well technically, thats not incorrect. Read-Only just means that you can get data from it, you just can't overwrite what is already there. So basically, you can get and use LocalPlayer, you just can't change LocalPlayer to something other than what it already is. dyler3 1510 — 9y
0
But uh, glad I could help :P dyler3 1510 — 9y
0
Ok... Now I know what wiki means when it says read only..... :p lucas4114 607 — 9y
Ad

Answer this question