Hi! I was working on a soda that kills you 0.5 seconds after you equip it. However, I just can’t seem to find a solution. Here’s my code so far:
local Press = Enum.KeyCode.E --- Variable to hold the letter I want
local UserInputService = game:GetService("UserInputService") --- InputService for Player
local Tool = game.StarterPack.Tool --- Finds The Tool in starterpack
local Character = game.Character --- The Players model
local Humanoid = Character.Humanoid --- The root part
local equipped = false
local tool = script.Parent
equipped = true
--- Trying To Kill The player Here, Deleted the old code cuz it was a mess
equipped = false
I STRONGLY suggest learning basic errors for Roblox scripting.
repeat wait() until tool.Parent ~= game:GetService("StarterPack")
if tool.Parent:FindFirstChild("Humanoid") then
equipped = true
local Hum = tool.Parent.Humanoid
Hum.Health -= Hum.MaxHealth
I have like 10 tabs open about scripting a day to learn it and I still haven’t learned the basics
I just found the scource of the error. It’s the variable referencing Hum. It keeps wanting to use a humanoid in starterpack when the player isn’t even related to that. However, I would have to find another scource instead of parent. Is there an alternative to parent?
local Hum = Tool.Parent.Humanoid
If you do however place a humanoid in starterpack, the sound plays instead of it not playing. So that’s a bonus I guess.
Edit: It’s just the Tool.Parent part of the line that causes the error
The problem here is the referencing of your tool. A tool in the StarterPack will be cloned into the Player’s Backpack when they join the game. This allows them to see the black transparent box everyone knows as a tool. When this tool is clicked the actual tool object will be parented to the player’s character. Now that we understand how tools work let’s fix your code.
Make sure the script you are using is a local script parented to the tool in studio. The Tool’s parent should be StarterPack.
Change the Tool variable to:
Tool = script.Parent
That is all. Don’t forget to mark this as a solution if it helped!