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

Leaderstats not working or what's the issue?

Asked by 6 years ago
Edited 6 years ago

When a pickaxe collides with the object it is supposed to give you raw robloxs (the in game currency), but it doesn't work. Any help would be appreciated.

local part = script.Parent.Handle
local oof = game:GetService("Workspace").Model.Oof
local leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats")

script.Parent.Touched:Connect(function(hit)
 if hit.Parent.Name == "Pick" then
  leaderstats('Raw Robloxs').Value = leaderstats('Raw Robloxs').Value + 5

 end
end)
0
Errors? 522049 152 — 6y
0
Workspace.Model.Oof.Script:10: unexpected symbol near '?' kittonlover101 201 — 6y
0
I don't see a '?' 522049 152 — 6y
0
I know. kittonlover101 201 — 6y
View all comments (6 more)
0
Which part is supposed to be the part that gives the currency, the handles? 522049 152 — 6y
0
Well once the handle touches the brick it will give the leaderstat. So the brick is the thing that is giving the money. kittonlover101 201 — 6y
0
Ok I see, at line 5 replace it with part.Touched:Connect(function(hit) 522049 152 — 6y
0
Try leaderstats['Raw Robloxs'].Value MooMooThalahlah 421 — 6y
0
Ok, i'll try. kittonlover101 201 — 6y
0
Still doesn't work. /: kittonlover101 201 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

The Touched event does not work in LocalScripts, and LocalPlayer is nil on the server. And you used () when it's [].

local part0 = script.Parent.Handle
local oof = game.Workspace.Model.Oof
local leaderstats -- We need to get the player before we do anything. Leave blank for now.
local playersService = game:GetService"Players"
local debounce = false -- if you don't want it to spam "Raw Robloxs" add this.

script.Parent.Touched:Connect(function(part)
    if not debounce and part.Parent.Name == "Pick" then
        local plr = playersService:GetPlayerFromCharacter(part.Parent.Parent)
        if plr then -- make sure it's a player
            debounce = true
            leaderstats = plr:WaitForChild"leaderstats"
            leaderstats["Raw Robloxs"].Value = leaderstats["Raw Robloxs"].Value + 5
            -- debounce = false -- Debounce reset logic can go here. Reset to false so the code can repeat. If you wish for it to not repeat, take this off and it can be a one time touch.
       end
    end
end)

script.Parent.TouchEnded:Connect(function(part)
    debounce = false -- Debounce logic can go here if you want it to reset after it stops touching.
end)
0
The script works, but for some weird reason it keeps on giving me money. kittonlover101 201 — 6y
0
What does Debounce logic mean? kittonlover101 201 — 6y
0
Debounce logic means to prevent it from detecting touch multiple times, so if you don't want it to give you alot of "Raw Robloxs" and want it to give you only 5 then you use debounce. User#21146 0 — 6y
Ad

Answer this question