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

Shop ServerSided script is not working?

Asked by 4 years ago
Edited 4 years ago

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)
0
It should give you a syntax error because you never wrote 'end)' after 'game.Players.PlayerAdded:Connect(function(plr)' fpnky 0 — 4y
0
ah, it did you're right, it still doesn't work though when I added it. FaZeMcKid 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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)

0
Keep in mind that this is a local script so the player won't actually have the tool on the server. EncapsuIation 450 — 4y
0
I have no clue how to give it to the player without it being in a local script FaZeMcKid 0 — 4y
Ad

Answer this question