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

Not giving the gear to the player? [SOLVED]

Asked by 6 years ago
Edited 6 years ago

Actual Error: (i'm really stupid lol) While testing the script below, I was coping the money bag and inserting it directly into my backpack, forgetting that I need the gear to be inserted through the server script. (which I had, but to save time I did the copy and paste.) Thanks to everyone to helped!

Trying to make a vending machine to when you have a moneybag, it will remove it and give it to the player.

Problem is that it never makes it past the

if already ~= nil then

Is there something I am doing wrong?

--//Variables
local clickdetector = script.Parent.ClickDetector
local sound = script.Parent.Sound

--//Code
clickdetector.MouseClick:Connect(function(plr)
print(plr.Name) --showing the player's name that clicked the button
    local already = plr.Backpack:FindFirstChild("Money Bag") --seeing if we can find the moneybag
    if already ~= nil then --checking if we found the moneybag
        print("Did this work?") 
        sound:Play() --playing sound
        plr.Backpack["Money Bag"]:Destroy() --removing the moneybag
        wait(0.2)
        print("success")
        game.Lighting.BloxyCola:Clone().Parent = plr.StarterGear --giving the cola to the player's starter pack
        game.Lighting.BloxyCola:Clone().Parent = plr.Backpack --giving the cola to the player's current backpack
    end
end)
0
Don't use Lighting as storage. Use ServerStorage and ReplicatedStorage instead, that's what they're for. Storage. User#24403 69 — 6y
1
will keep noted. meteorcrasher118 35 — 6y
0
I believe that only the client can access tools from their Backpack. For the server the Backpack shows that it's empty (unless you add a tool in the player's backpack using a server script) awesomeipod 607 — 6y
0
yeah, i added in the tool using a server script. meteorcrasher118 35 — 6y
View all comments (4 more)
0
Do you send Money Bag through a server script or remote event? yHasteeD 1819 — 6y
0
server script meteorcrasher118 35 — 6y
0
Try to remove "~= nil" yHasteeD 1819 — 6y
0
You script is fine, it works but you probably used LocalScript, use Server Script. Place it inside the part. Place the sound and the ClickDetector inside the part too. This works, I checked it. HeyItzDanniee 252 — 6y

Answer this question