Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

How can I find a player in the real server?

Asked by 5 years ago

(sorry if the title is misleading, I couldn't convert it to a question. The original name was "FindFirstChild question")

So I am making a script where I want a person to touch a brick and it falls down on them (already made) and when the brick touches the ground, it will kill the person.

The output shows nothing because I can't see it during a real game and in studio my player is named "Player"

So I did:

 wait(1)
death1 = game.Workspace.Box

 function onTouch(hit)
    death1.CanCollide = false
    game.Workspace:FindFirstChild("Box")
    if "Box" ~= nil then
        death1.CFrame = CFrame.new(120, 18, -475)
        wait(0.2)
        death1.CFrame = CFrame.new(120, 11, -475)
        wait(0.2)

   local b = game.Workspace.Player:FindFirstChild("Humanoid")
        if b ~= nil then
            b.Health = 0
    end

        wait(3)
        death1.CanCollide = true
        if b.Health == 0 then
            death1.CFrame = CFrame.new(120, 18, -475)
            death1.CanCollide = false

 script.Parent:connect(onTouch)

now this all works fine.

BUT

When I get out of studio and test it, it just falls down and do nothing. I know why it doesn't, because in workspace it doesn't find "Player" because my username isn't player.

So my question is, how would I find a player and kill them if their name isn't "player'?

This would be really nice if I could get it to work.

1 answer

Log in to vote
0
Answered by
NotSoNorm 772 Moderation Voter
5 years ago

Alright, So what you're trying to do is go directly to the 'Player' from workspace, because you put it as game.Workspace.Player it only goes to a person named player, but since you're not named player, it breaks.

So what you could do is get the hit of the player and then find their humanoid

*Normal script: *

--You defined what 'hit' was in your beginning function
local b = hit.Parent:FindFirstChild("Humanoid")

The onTouched event returns the part that touched it, because your player touched it, It returns the part of the player and simply get the humanoid from the parent.

0
This wouldn't work well since you're handling this locally. Lacryma 547 — 5y
0
I didn't want to go into detail with the on touched event, I said to find a work around, because there are plenty. NotSoNorm 772 — 5y
0
Not that, the script you had before was in a local script and using the parent of the script to call the touch event which is incorrect. Lacryma 547 — 5y
Ad

Answer this question