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

how do i get all the player in game not just local player?

Asked by 5 years ago

i want to make a script when it hits a player that player get bluer but idk how do i get all the player ib game

0
use a for i,v in pairs() do loop User#23365 30 — 5y
0
but i just want to get one of them the one that got hit helleric -3 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

I'm not sure what you mean by "not just local player" as server scripts cannot get the local player but to get the player that is hit, first create a on touched event:

script.Parent.Equipped:Connect(function()
    equipped = true
    char = script.Parent.Parent
    humanoid = char:FindFirstChild("Humanoid")
end)

script.Parent.Unequipped:Connect(function()
    equipped = false
    char = nil
    humanoid = nil
end)

script.Parent.Handle.Touched:Connect(function(hit)
    if hit and equipped and char and humanoid and humanoid.Health > 0 then
        local targetHum = hit.Parent:FindFirstChild("Humanoid")
        if targetHum then

        end
    end
 end)

this checks if the tool is equipped, if the player character exists, and if the humanoid exists then checks if it hit something w/ a humanoid like a zombie or a player then:

local dmg  = 15

script.Parent.Equipped:Connect(function()
    equipped = true
    char = script.Parent.Parent
    humanoid = char:FindFirstChild("Humanoid")
end)

script.Parent.Unequipped:Connect(function()
    equipped = false
    char = nil
    humanoid = nil
end)

script.Parent.Handle.Touched:Connect(function(hit)
    if hit and equipped and char and humanoid and humanoid.Health > 0 then
        local targetHum = hit.Parent:FindFirstChild("Humanoid")
        if targetHum then
            local HitChar = targetHum.Parent
            targetHum:TakeDamage(dmg)
            if HitChar then
                for _,v in pairs(HitChar:GetChildren())
                    if v:IsA("BasePart") then
                        v.Color = Color3.fromRGB(9, 137, 207)
                    end
                end
            end
        end
    end
 end)

so this also damages the humanoid that was hit and cycles through all parts of the character that was hit and if it is a base part, (mesh part, truss part, corner wedge, etc.), then changes the color of it to blue.

0
it dose not get IF helleric -3 — 5y
0
what do you mean IF? theking48989987 2147 — 5y
0
never mind i fixed lol helleric -3 — 5y
0
props theking48989987 2147 — 5y
Ad

Answer this question