Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make the player not take damage from his own abilities?

Asked by 2 years ago

basically if the player goes into the abilities area of damage they also take damage how am i able to prevent the player from damaging themselves without become invincible?

this is the script that i use to create the damage:

wait(1)
function onTouched(part) 
    local h = part.Parent:findFirstChild("Humanoid") 
    if h~=nil then 
        h.Health = h.Health -2  --Change that number to the ammount of Health you want to decrease
    end 
end 

script.Parent.Touched:connect(onTouched)

video to better explain

0
try adding something like if h ~= game.Players.LocalPlayer then zokizoram2 0 — 2y

3 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Try using ObjectValues

The only problem I'm seeing is with the script you posted with the question.

You can't find the player, maybe try asking the server script(the one that gets the remote) for the player.

My guess is that one of the clones contain the script, you'll need to add a ObjectValue and set the property "Value" to the player.

wait(1)
local ObjectValue=script.LocalPlayer
local Damage=2
function onTouched(part) 
    local h = part.Parent:findFirstChild("Humanoid") 
    if h~=nil then 
        if game:GetService("Players"):GetPlayerFromCharacter(part.Parent)~=ObjectValue.Value then
            h.Health = h.Health - Damage
        end
    end 
end 

script.Parent.Touched:connect(onTouched)
0
Sorry for the text clipping. MiAiHsIs1226 189 — 2y
0
it isnt from a tool. pressing E summons the ability so yeah SmAsHBrooS 2 — 2y
0
? MiAiHsIs1226 189 — 2y
0
So you're saying, it is from a keybind, if it is a keybind then you get it from a player. MiAiHsIs1226 189 — 2y
View all comments (12 more)
0
it isnt a tool SmAsHBrooS 2 — 2y
0
Does it use remotes? If so, can you place links for the scripts MiAiHsIs1226 189 — 2y
0
Ik it isn't from a tool. MiAiHsIs1226 189 — 2y
0
Oh yes it does use remotes, ill put the scripts in a pastebin hold on SmAsHBrooS 2 — 2y
0
(Sorry if I have bad english) MiAiHsIs1226 189 — 2y
0
https://ghostbin.com/zELNW / this and the other script are seperate, because i couldnt find a way to implement it all in one script SmAsHBrooS 2 — 2y
0
Wait.. Why are there two damage scripts? Do you use the damage script that you placed on the post? MiAiHsIs1226 189 — 2y
0
yes, the script in the ghostbin basically does this: when it hits a humanoid it deals 20 damage and starts the impact tween. it also makes it so if you hit a wall it starts the impact tween aswell / what i did was i placed the script in the post above inside of the brick thats caused after the explosion / i can provide screenshots to be clearer SmAsHBrooS 2 — 2y
0
Please send screenshots MiAiHsIs1226 189 — 2y
0
Ok I've come up with a solution(The image wasn't loading so I had to read the message you said and I just realized) MiAiHsIs1226 189 — 2y
0
I'll update my answer MiAiHsIs1226 189 — 2y
Ad
Log in to vote
0
Answered by
SuperPuiu 497 Moderation Voter
2 years ago

if it is a local script you can:

local plyr = game.Players.LocalPlayer
wait(1)
function onTouched(part) 
    local h = part.Parent:FindFirstChild("Humanoid") 
    if h~=nil then
        if h ~= plyr.Character.Humanoid then
        h.Health = h.Health -2  --Change that number to the ammount of Health you want to decrease
    end 
end
end 

script.Parent.Touched:Connect(onTouched)

If it is a server script then you have to upload all your script

0
Its a server script but i tried your code as both local and server and it didnt work SmAsHBrooS 2 — 2y
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

try this script


local lplr = game.Players.LocalPlayer function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil and h ~= lprl then --if h isnt nil and if h isnt = local player then h.Health = h.Health -2 end end script.Parent.Touched:connect(onTouched)
0
Still damages player :( SmAsHBrooS 2 — 2y

Answer this question