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)
The Touched
event does not work in LocalScript
s, 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)