Hi, I have an issue where my local script inside a tool doesn’t work when I click it while it’s equipped.
local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2125938751
function onActivation()
if BadgeService:UserHasBadge(player.UserId, BadgeId) then
error.SoundId = "rbxassetid://2124914240"
script.Parent.Handle.Decal:Destroy()
script.Parent.Handle.BrickColor = BrickColor.new("Really red")
if not error.IsLoaded then
error.Loaded:wait()
end
error:Play()
error.Stopped:Connect(function(soundId)
error:Destroy()
character.Humanoid.Health = 0
end)
else
character.Humanoid.Health = 0
end
end
tool.Activated:Connect(onActivation)
Basically, I wanna make a tool where you hold a gift and once clicked, check’s if you have the badge. If it does then it would kill you. If not, rewards you a badge (kind of like some sort of consequence towards a player who steals gifts.)
Anyone knows how to fix it?
Edit 1: I have found a workaround from the script not working. The local character = player.CharacterAdded:wait()
was the issue so I moved it to the character.Humanoid.Health = 0
to player.Character.Humanoid.Health = 0
. I’v also added the local error = Instance.new("Sound", game.Workspace)
, kinda forgot to do it.
This isn’t really the end as now the if BadgeService:UserHasBadge(player.UserId, BadgeId) then
isn’t working. It print’s out as a index nil error on the UserId. Anyone can help?