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

Help with an event firing when a player touches another player? [SOLVED]

Asked by 9 years ago

Hello there, I have already asked a question like this, but I still can't figure it out. As it says in the title, I'm having a bit of trouble with this script.

local a = math.random(1, game.Players.NumPlayers)
plyrs = game.Players:GetChildren()
for i = 1, #plyrs do
    rand = plyrs[a]
end
character = rand.Character
print("Player chosen: "..rand.Name)

wait(1)

character.Torso.Touched:connect(function(hit)
local touched = game.Players:GetPlayerFromCharacter(hit.Parent)
if touched then
    print(rand.Name.." touched ".. touched.Name.."!")
end
end)

I am just analysing this script and I do not claim this script is mine. I'm just trying to understand it, but whenever I start a 2 player server, the print(rand.Name.."touched"..touched.Name.."!") does not show in the output. Could anyone tell me what is wrong with the script? Oh and also, this is not the whole script, so sorry if I missed anything in it

1
Try removing the "if touched then" Because you already have the function touched. woodengop 1134 — 9y
0
Ok I'll try that vivaftw 5 — 9y
3
Continent, that is checking to make sure the player isn't null or some other object. Having that there is necessary to limit it to players DigitalVeer 1473 — 9y
0
Oh wait, I fixed it thanks. It was my fault in the rest of the script, Sorry but thanks for helping. vivaftw 5 — 9y
0
TheContinentofEurope's confusion was because of a *bad variable name*. Name your variables well. Perci1 4988 — 9y

Answer this question