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

Gun shop script doesn't work?

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

✓ Accepted answer

##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

4 comments

0

Hmm, thanks, I used FindFirstChild because the wiki said LocalPlayer was read only, but I guess the wiki was wrong then. XD

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.

0

But uh, glad I could help :P

0

Ok... Now I know what wiki means when it says read only..... :p

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