Trying to get a player from a server script inside a gui

You can write your topic however you want, but you need to answer these questions:

  1. Im trying to make it so that after a timer hits 0, that all the players get teleported to the arena Keep it simple and clear!

  2. I can’t figure out how to get the player Include screenshots / videos if possible!

  3. I tried using :GetPlayerFromCharacter() but it doesnt seem to have worked Did you look for solutions on the Developer Hub?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local timevalue = script.Parent.Time

timevalue.Changed:Connect(function()
	script.Parent.Text = timevalue.Value
	if timevalue.Value == 0 then
		local e =
			e.Character.PrimaryPart.CFrame = CFrame.new(17, 470.5, -257)
			local glove = e.leaderstats.Glove.Value
			local glove2 = game:GetService("ServerStorage").Gloves:FindFirstChild(glove)
			glove2:Clone().Parent = e.Backpack
			e.PlayerGui.HUD.Power.LocalScript.Enabled = true
		script.Parent.Parent:Destroy()
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

To do it for every player try doing this

local timevalue = script.Parent.Time
timevalue.Changed:Connect(function()
	script.Parent.Text = timevalue.Value
	if timevalue.Value == 0 then
		for i,player in ipairs(game:GetService("Players"):GetPlayers()) do
			player.Character.PrimaryPart.CFrame = CFrame.new(17, 470.5, -257)
			local glove = e.leaderstats.Glove.Value
			local glove2 = game:GetService("ServerStorage").Gloves:FindFirstChild(glove)
			glove2:Clone().Parent = e.Backpack
			e.PlayerGui.HUD.Power.LocalScript.Enabled = true
			script.Parent.Parent:Destroy()
		end
	end
end)

Basically add your code to

for i,player in ipairs(game:GetService("Players"):GetPlayers()) do
	--Your Code
end

I tried it and it works but the code gets run the amount of times how many players there are in the game
Basically if there are 2 players those 2 players will get teleported twice and receive the same tool twice too
or if there are 4 those players will get teleported 4 times and receive the same tool 4 times and so on
Im not sure how to explain it very well

try instead of ipairs pairs idk whats the difference

wait nvm i found out the way to fix it, welp thanks for the help anyway

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.