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

My team changing script is only happening on the users screen and not globally?!?!

basically im making a game, and the guns i use force shiftlock, so i cant use mouse clicking to change teams, so i use a hotkey to do it, it looks like you changed team but thats only on your screen for some reason, because your actual team is your previous team, how i know is because i spawn on the wrong spawn

THIS IS ON A LOCAL SCRIPT

local player = script.Parent.Parent.Parent.Parent.Parent
local mouse = player:GetMouse();

mouse.KeyDown:connect(function(key)
	if key == "n" then -- Change key to whatever you want
		player.Character.Humanoid.Health = 0
		wait(5)
		player.Team = game.Teams:FindFirstChild("Immigrants")
	end
end)

TIPS: -- i used a Regular Script, but the code has an error on mouse.KeyDown:connect(function(key) bit

-- i tried template free models, they didn't help

1 comment

1

Use Remote Events

1 answer

✓ Accepted answer

The reason why this wouldn't work is that it is all on a local script. You would want to use remote events to change a player's team.

ServerScript (place in ServerScriptService):

local event = Instance.new('RemoteEvent', game.ReplicatedSorage)
event.Name = "KeyPressed"
event.OnServerEvent:Connect(function(player)
	player.Team = game.Teams:FindFirstChild("Immigrants")
end)

LocalScript (wherever it originally was (recommended for StarterPlayerScripts)):

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local event = game.ReplicatedStorage:WaitForChild("KeyPressed")

mouse.KeyDown:connect(function(key)
    if key == "n" then -- Change key to whatever you want
        player.Character.Humanoid.Health = 0
        wait(5)
        event:FireServer()
    end
end)

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