G’Day all
I’m super new to scripting and this is my first post so hopefully everything is correct, I am looking for some help to work out what I’ve done wrong.
-
I want to change multiple bricks color and material properties when more than 1 player steps on a brick
-
Color and material changing function is not working and is not printing after its called
-
I spent hours searching through Topics on here as well as Dev Hub and YouTube. I can get it to work using a different script but just for one player.
This script will eventually teleport players touching the brick to a map. Didn’t go any further as i hit this problem. All prints work except for the one that is located under where the “LightUpXtremeTeleportRing” function is called. No errors or warnings in the output.
local TouchingPlayers = {}
function LightUpXtremeTeleportRing()
for _, object in pairs(game.Workspace.Lobby.LobbyXtremeTeleport:GetChildren()) do
if object.Name == "Ring" then
object.Material = ("Neon")
object.BrickColor = BrickColor.new("Lime green")
end
end
end
function LightTeleportRingDisabled()
for _, object in pairs(game.Workspace.Lobby.LobbyXtremeTeleport:GetChildren()) do
if object.Name == "Ring" then
object.Material = ("Plastic")
object.BrickColor = BrickColor.new("Really red")
end
end
end
XtremeTeleportPad.Touched:Connect(function(Hit)
if game.Players:GetPlayerFromCharacter(Hit.Parent) then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
table.insert(TouchingPlayers, Player)
print("player Added")
end
end)
XtremeTeleportPad.TouchEnded:Connect(function(Hit)
if game.Players:GetPlayerFromCharacter(Hit.Parent) then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
table.remove(TouchingPlayers, table.find(TouchingPlayers, Player))
print("Player Left")
end
end)
while #TouchingPlayers > 1 do
wait(1)
XtremeTeleportPad.Touched:Connect(LightUpXtremeTeleportRing)
print("Launching")
end
while #TouchingPlayers < 2 do
wait(1)
XtremeTeleportPad.TouchEnded:Connect(LightTeleportRingDisabled)
print("Need More Players")
end
--[[Teleport To Map]]--
Any help, tips or recommendations would be greatly appreciated.
Cheers
I recommend putting the Player Check when the pad is touched. Also, don’t use loops.
1 Like
Thanks for the reply I will give it a go.
1 more thing. If you are going to use loops, always use
game.RunService.Heartbeat:Connect(function()
end)
They’re way better than while true do
loops.
3 Likes
Ok thanks, I will try to change it to have no loops first.
1 Like
How would I go about selecting/changing multiple parts without using a loop? The 3 ways I know how to are all loops.
Sorry, don’t think I made it clear.
I meant loops like
while true do
while something > x do
Loops like
for i, v in pairs(someObj) do
are completely fine.
1 Like
awesome that worked, I made these changes and it lights up when more than 1 person is touching but it is flashing on and off I guess do to my animation making the player move, not sure if this will create another problem later on when I try to teleport.
local TouchingPlayers = {}
function LightUpXtremeTeleportRing()
for _, object in pairs(game.Workspace.Lobby.LobbyXtremeTeleport:GetChildren()) do
if object.Name == "Ring" then
object.Material = ("Neon")
object.BrickColor = BrickColor.new("Lime green")
end
end
end
function LightTeleportRingDisabled()
for _, object in pairs(game.Workspace.Lobby.LobbyXtremeTeleport:GetChildren()) do
if object.Name == "Ring" then
object.Material = ("Plastic")
object.BrickColor = BrickColor.new("Really red")
end
end
end
XtremeTeleportPad.Touched:Connect(function(Hit)
if game.Players:GetPlayerFromCharacter(Hit.Parent) then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
table.insert(TouchingPlayers, Player)
if #TouchingPlayers > 1 then
wait(1)
XtremeTeleportPad.Touched:Connect(LightUpXtremeTeleportRing)
print("Players Added Now Launching")
end
end
end)
XtremeTeleportPad.TouchEnded:Connect(function(Hit)
if game.Players:GetPlayerFromCharacter(Hit.Parent) then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
table.remove(TouchingPlayers, table.find(TouchingPlayers, Player))
if #TouchingPlayers < 2 then
wait(1)
XtremeTeleportPad.TouchEnded:Connect(LightTeleportRingDisabled)
print("Need More Players To Launch")
end
end
end)```
I must of made a mistake somewhere as when 1 player steps of the brick it continues to flash and doesn’t print “need more players to launch”
Bad line, putting an event inside another event. Just call the function like this:
LightTeleportRingDisabled()
1 Like
Its now activating when only 1 player is touching but the flashing has stopped
Could you show me your code and output, please?
1 Like
local TouchingPlayers = {}
function LightUpXtremeTeleportRing()
for _, object in pairs(game.Workspace.Lobby.LobbyXtremeTeleport:GetChildren()) do
if object.Name == "Ring" then
object.Material = ("Neon")
object.BrickColor = BrickColor.new("Lime green")
end
end
end
function LightTeleportRingDisabled()
for _, object in pairs(game.Workspace.Lobby.LobbyXtremeTeleport:GetChildren()) do
if object.Name == "Ring" then
object.Material = ("Plastic")
object.BrickColor = BrickColor.new("Really red")
end
end
end
XtremeTeleportPad.Touched:Connect(function(Hit)
if game.Players:GetPlayerFromCharacter(Hit.Parent) then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
table.insert(TouchingPlayers, Player)
if #TouchingPlayers > 1 then
wait(1)
LightUpXtremeTeleportRing()
print("Players Added Now Launching")
end
end
end)
XtremeTeleportPad.TouchEnded:Connect(function(Hit)
if game.Players:GetPlayerFromCharacter(Hit.Parent) then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
table.remove(TouchingPlayers, table.find(TouchingPlayers, Player))
if #TouchingPlayers < 2 then
wait(1)
LightTeleportRingDisabled()
print("Need More Players To Launch")
end
end
end)
just trying to work out how to upload the output
You can use snipping tool, and CTRL+V it
1 Like
Could you also post your script, please?
1 Like
local XtremeTeleportPad = game.Workspace.Lobby.LobbyXtremeTeleport.LobbyXtremeTeleportPad
local TouchingPlayers = {}
function LightUpXtremeTeleportRing()
for _, object in pairs(game.Workspace.Lobby.LobbyXtremeTeleport:GetChildren()) do
if object.Name == "Ring" then
object.Material = ("Neon")
object.BrickColor = BrickColor.new("Lime green")
end
end
end
function LightTeleportRingDisabled()
for _, object in pairs(game.Workspace.Lobby.LobbyXtremeTeleport:GetChildren()) do
if object.Name == "Ring" then
object.Material = ("Plastic")
object.BrickColor = BrickColor.new("Really red")
end
end
end
XtremeTeleportPad.Touched:Connect(function(Hit)
if game.Players:GetPlayerFromCharacter(Hit.Parent) then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
table.insert(TouchingPlayers, Player)
if #TouchingPlayers > 1 then
wait(1)
LightUpXtremeTeleportRing()
print("Players Added Now Launching")
end
end
end)
XtremeTeleportPad.TouchEnded:Connect(function(Hit)
if game.Players:GetPlayerFromCharacter(Hit.Parent) then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
table.remove(TouchingPlayers, table.find(TouchingPlayers, Player))
if #TouchingPlayers < 2 then
wait(1)
LightTeleportRingDisabled()
print("Need More Players To Launch")
end
end
end)
Hmm… not sure what’s wrong.
(TEXT-TEXT)
1 Like
Well thanks for the time and effort you have given it. Greatly appreciated
1 Like