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

How to get the player from the character?

Asked by
Desmondo1 121
3 years ago

In my win system. I made a local script in startergui to show the person who won. The issue is that since it is in startergui, the local script is cloned to everyone. I need it to just show for the winner of the round.

Heres my script: (Btw, I don't actually have anything yet because I'm completely stumped on how I would reference the player from the character)

place = CFrame.new(102.4, 205.2, 210.8)

script.Parent.Touched:connect(function(p)

local humanoid = p.Parent:findFirstChild("Humanoid")

if (humanoid ~= nil) then

    humanoid.Torso.CFrame = place 

    game.StarterGui.Win.showwin.Parent = 


    _G.InsideBossBattle = true
    game.ReplicatedStorage.NotWonYet.Value = false

    game.ReplicatedStorage.ShowWin:FireAllClients()

    local target = CFrame.new(114.2, 205.8, 211.7) 
    for i, player in ipairs(game.Players:GetChildren()) do

        if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then

            player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0)
        end
    end

    game.Workspace.WinningMusic.Playing = true
    game.Workspace.BGMusic.Playing = true
    game.Workspace.GameMusic.Playing = false

    for i=1, 20 do
        game.Workspace.BGMusic.Volume = game.Workspace.BGMusic.Volume - 0.05

    game.Workspace.WinningMusic.Playing = true
    game.Workspace.WinningMusic.Volume = game.Workspace.WinningMusic.Volume + 0.05

        wait(0.3)

    end
    wait(3.5)

    game.Workspace.BGMusic.Playing = true

    for i=1, 20 do
        game.Workspace.BGMusic.Volume = game.Workspace.BGMusic.Volume + 0.05


        game.Workspace.WinningMusic.Volume = game.Workspace.WinningMusic.Volume - 0.05

        wait(0.3)

    end
    game.Workspace.WinningMusic.Playing = false
    game.Workspace.WinningMusic.TimePosition = 54

    humanoid.Parent.showwin.Parent = game.StarterGui

end

end)

2 answers

Log in to vote
1
Answered by 3 years ago

You can also do

game.Players[ch.Name]

This is because using . in place of [] is a shortcut. f you aren't using a literal string, use []

0
Thanks, that fixed most of my script. Desmondo1 121 — 3y
Ad
Log in to vote
0
Answered by
Nootian 184
3 years ago
game.Players:GetPlayerFromCharacter(ch)
0
I don't think you understand what I'm trying to do. In my script, when a player touches the end of the obby. It fires a remote event to a local script to make the gui show up. But since the local script gets cloned to everyone. The gui shows up for everyone. I can't just reference all players. I need to reference the player who won. As you can see, in the script I already have the character. But I Desmondo1 121 — 3y
0
(This is continuing my other comment that was too long) don't have the player. Desmondo1 121 — 3y

Answer this question