hey eveyone, i have a spawnlocation that switches teams form civillian to police (no child scripts for the spawner) and i also have a script that gives specific teams players ex. police get handcuffs. the only problem is that when a player switches teams they have to reset to get the items for that team and i made the respawn time really slow so it can be boring waiting to respawn after switching teams. anyone have any solutions?
You could take advantage of the Team property being changed.
Some variation of the following should work:
local playerService = game:GetService('Players');
playerService.PlayerAdded:Connect(function(Player)
Player:GetPropertyChangedSignal('Team'):Connect(function()
if Player.Team.Name == 'Police' then
-- Insert tools
else
-- Remove tools
end;
end);
end);
You could use the Players:LoadCharacter(spawnLocation)
function so the character spawns instantly.
I’ve never seen someone use ;
in their Roblox scripting
well here is the thing, i already have a script for giving a specific team tools, so adding it to another script would crowd the hotbar with duplicates of items. and i dont want to delete the current one in case the new one does not work.
this will kinda help if i use this with part of the other script but i cant find a full answer
um how do i remove tools? and also i think this might work! ill test it soon
ok i kinda wentr off what you both said like this:
playerService.PlayerAdded:Connect(function(Player)
Player:GetPropertyChangedSignal('Team'):Connect(function()
if Player.Team.Name == 'Police' then
playerService:LoadCharacter(spawnLocation)
else
end;
end);
end);
and now its not working, can you please tell me why? i suspect it has to do with the “playerservice:loadcharacter(spawnlocation)” but i dont know how to fix it
The semicolons do nothing to the script, some people just like it that way - maybe because it looks easier to read for them
i think this is off topic, can someone please help me with my script?
:LoadCharacter()
does not take any parameters.
thank, btw im new to the lua language so can u pls tell me what a paramiter is?
It’s what you send through a function
function printTwice(message, inOneMessage)
if inOneMessage then
print(message, message)
else
print(message)
print(message)
end
end
--message and inOneMessage are the arguments (the parameter but receiving not passing)
printTwice("Hello!!!!", true)
--"Hello!!!!" and true are the parameters
ok thank you for helping me expand my knowledge, i will now go test some more code
i have now changed the script and tested it…
playerService.PlayerAdded:Connect(function(Player)
Player:GetPropertyChangedSignal('Team'):Connect(function()
if Player.Team.Name == 'Police' then
Player:LoadCharacter()
else
end;
end);
end);
and it works! thank you all for helping me fix another problem i have! i wish i could mark multiple solutions cuz i kinda used a combination of two peoples solutions and then you helped fix the code
game.Players.PlayerAdded:Connect(function(player)
player:GetPropertyChangedSignal("Team"):Connect(function()
player:LoadCharacter()
end)
end)
is that just to help me simpify my code to make it more readable?
looking at the code, that is not only simpler, but solves my problems with changing other teams as well! all i have to do is test it
the original purpose was to help for the other teams, but now looking at it, it is more readable