Hanadtv
(Hanad)
January 7, 2023, 11:31pm
#1
i made a script that kills the player when it is activated
local tool = script.Parent
local player = game:GetService("Players"):GetPlayerFromCharacter(tool.Parent)
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
tool.Activated:Connect(function()
humanoid:TakeDamage(100)
end)
i don’t understand why it isn’t working
This doesn’t seem to make sense, you can just condense this to
local character = tool.Parent
Also, can you describe what you mean by “not working”?
Hanadtv
(Hanad)
January 7, 2023, 11:34pm
#3
well when the tool is activated it’s supposed to make the humanoid take damage
you could try
script.parent.activated:Connect(function(hit)
local char = workspace:findfirstchild(hit.Name)
char.Humanoid.Health = 0
end)
I know, but what’s the issue? Is the script not running? Is the player not fullying dying?
Hanadtv
(Hanad)
January 7, 2023, 11:36pm
#6
yeah its not dying like i made the script to do
You can insert math.huge
into the Humanoid:TakeDamage
parameters or just set the humanoid health to 0 like @Callum_Cloth suggested:
humanoid:TakeDamage(math.huge)
you can by doing
char.humanoid.Health = char.humanoid.Health - number
DasKairo
(Cairo)
January 7, 2023, 11:40pm
#10
You can
With Humanoid.Health
you can just set its health
Humanoid:TakeDamage()
is a function for Humanoids to take Damage, the only difference is that you cant add with Humanoid:TakeDamage()
Hanadtv
(Hanad)
January 7, 2023, 11:40pm
#11
alright i’ll see if that works
Hanadtv
(Hanad)
January 7, 2023, 11:43pm
#12
unfortunately that didn’t as well
Did you try this yet?
script.parent.activated:Connect(function(hit)
local char = workspace:findfirstchild(hit.Name)
char.Humanoid.Health = 0
end)
but that in a normal script in the tool
is there any errors in output?
Hanadtv
(Hanad)
January 7, 2023, 11:45pm
#15
15:45:33.640 Script ‘Players.H2nad.Backpack.Instant Death.Script’, Line 3 - Studio - Script:3
15:45:33.640 Stack End - Studio
not seeing anything out of the ordinary
can i see whats the current script you are using?
Hanadtv
(Hanad)
January 7, 2023, 11:47pm
#17
local tool = script.Parent
local player = game:GetService("Players"):GetPlayerFromCharacter(tool.Parent)
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local function instantkill ()
humanoid:TakeDamage(100)
end
tool.Activated:Connect(instantkill)
is the script context local ? also have you tried this script yet
script.parent.activated:Connect(function(hit)
local char = workspace:findfirstchild(hit.Name)
char.Humanoid.Health = 0
end)
DasKairo
(Cairo)
January 7, 2023, 11:48pm
#19
Also. The code you are running at the beginning, It will only run once, Are you sure you have access to the Player? And are you sure it isnt nil?
Hanadtv
(Hanad)
January 7, 2023, 11:49pm
#20
yes, that didn’t work either :((
try adding a print under the player (print the player variable)
see if its returning nil or not