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

Shop ServerSided script is not working?

When I click the button to buy a sword, it doesn't say any errors or give me the sword.

script.Parent.MouseButton1Click:Connect(function()
	game.Players.PlayerAdded:Connect(function(plr)
		local RS = game:WaitForChild("ReplicatedStorage")
    local library = RS:WaitForChild("Library")
    local tool = library.ClassicSword
    if plr.leaderstats.Cash.Value >= 1 then
        print("enough")
        local clone = tool:Clone()
        clone.Parent = plr.Backpack
    elseif plr.leaderstats.Cash.Value < 1 then
        print("not enough")
    end
end)
end)

2 comments

0

It should give you a syntax error because you never wrote 'end)' after 'game.Players.PlayerAdded:Connect(function(plr)'

0

ah, it did you're right, it still doesn't work though when I added it.

1 answer

You are creating an event listener for when the Mousebutton1Click fires. Then each time that fires you create a new listener for when player joins.

I think you are trying to get something like this

local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
        local RS = game:WaitForChild("ReplicatedStorage")
    local library = RS:WaitForChild("Library")
    local tool = library.ClassicSword
    if plr.leaderstats.Cash.Value >= 1 then
        print("enough")
        local clone = tool:Clone()
        clone.Parent = plr.Backpack
    elseif plr.leaderstats.Cash.Value < 1 then
        print("not enough")
    end
end)

2 comments

0

Keep in mind that this is a local script so the player won't actually have the tool on the server.

0

I have no clue how to give it to the player without it being in a local script

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