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

Help with player-player collisions?

Asked by 4 years ago
function touched(body)
    body.HumanoidRootPart.Touched:Connect(function(hit)
        local otherPlayer = game.Players[hit.Parent.Name]
        print(otherPlayer)
        if otherPlayer == game.ServerScriptService.RoundHandler.EnemyPlayerName.Value then
            script.Parent.Humanoid.Health = 0
        end
    end)
end
game.Players.PlayerAdded:Connect(function(newPlayer)
    newPlayer.CharacterAdded:Connect(touched)
end)

the player is supposed to be killed when the player with enemyplayername name touches the person. the script doesn't work.

1 answer

Log in to vote
0
Answered by
Rinpix 639 Moderation Voter
4 years ago

You're comparing an instance of a player to a string that supposedly contains their name.

So, instead of doing this:

if otherPlayer == EnemyPlayerName.Value then
    script.Parent.Humanoid.Health = 0
end

You do this:

if otherPlayer.Name == EnemyPlayerName.Value then
    script.Parent.Humanoid.Health = 0
end

Think of it like the concept of like terms in math. You can't compare unlike terms in math, just as you can't compare unlike data types in computer programming.

0
I'm also kind of confused as to what your script is actually doing. It looks like it's inside of your character, and whenever someone else touches the enemy player, you die? Wouldn't you tailor it to kill you when you touch the enemy player and not when someone else touches the enemy player? Just a little confused is all. Rinpix 639 — 4y
0
Sorry, When i touch the enemy player I'm supposed to die. barfpillow99 28 — 4y
0
and also game.Players[hit.Parent.Name] <-- the string is right there, it's getting the name barfpillow99 28 — 4y
0
No. It's not getting the name. It's getting the instance of the player that has the name you provided. Rinpix 639 — 4y
Ad

Answer this question