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.
01 | local part = script.Parent.Handle |
02 | local oof = game:GetService( "Workspace" ).Model.Oof |
03 | local leaderstats = game.Players.LocalPlayer:WaitForChild( "leaderstats" ) |
04 |
05 | script.Parent.Touched:Connect( function (hit) |
06 | if hit.Parent.Name = = "Pick" then |
07 | leaderstats( 'Raw Robloxs' ).Value = leaderstats( 'Raw Robloxs' ).Value + 5 |
08 |
09 | end |
10 | end ) |
The Touched
event does not work in LocalScript
s, and LocalPlayer
is nil on the server. And you used ()
when it's []
.
01 | local part 0 = script.Parent.Handle |
02 | local oof = game.Workspace.Model.Oof |
03 | local leaderstats -- We need to get the player before we do anything. Leave blank for now. |
04 | local playersService = game:GetService "Players" |
05 | local debounce = false -- if you don't want it to spam "Raw Robloxs" add this. |
06 |
07 | script.Parent.Touched:Connect( function (part) |
08 | if not debounce and part.Parent.Name = = "Pick" then |
09 | local plr = playersService:GetPlayerFromCharacter(part.Parent.Parent) |
10 | if plr then -- make sure it's a player |
11 | debounce = true |
12 | leaderstats = plr:WaitForChild "leaderstats" |
13 | leaderstats [ "Raw Robloxs" ] .Value = leaderstats [ "Raw Robloxs" ] .Value + 5 |
14 | -- 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. |
15 | end |