Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 comments

0

use a for i,v in pairs() do loop

0

but i just want to get one of them the one that got hit

1 answer

✓ Accepted answer

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.

4 comments

0

it dose not get IF

0

what do you mean IF?

0

never mind i fixed lol

0

props

This discussion is preserved as it was. New answers, comments, and votes are closed.