Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Trying to make players team change server side?

Asked by 4 years ago

So basically what I am trying to do is to make my Local Team changer to change the players team color in server side so it appears to other players I have already made a remote event in my game I am just confused about how to script it so it fires the players team color so the players team can happen in the server. I am a Semi Medium level scripter so I need some learning to do. My Local Script works good but I want to make the players team appear on the server side. If you are confused just reply on why you are confused.

Here is the script btw

script.Parent.Enabled = true
local P = game.Players.LocalPlayer
local H = P.Character
local Dbutton = script.Parent.background.deploy
local text = script.Parent.background.teamselected
local teamchanged = game.ReplicatedStorage.Teamevents.TeamChanged ------Remote Event for help
Dbutton.Visible = false
function SEF()
    P.TeamColor = game.Teams["Special Emergency Forces"].TeamColor
    text.Text = "Special Emergency Forces"
    Dbutton.Visible = true

end
script.Parent.background.sef.MouseButton1Click:Connect(SEF)
function RBN()
    P.TeamColor = game.Teams["Red Bacon Navy"].TeamColor
    text.Text = "Red Bacon Navy"
    Dbutton.Visible = true

end 
script.Parent.background.rbn.MouseButton1Click:Connect(RBN)
function RBA()
    P.TeamColor = game.Teams["Red Bacon Army"].TeamColor
    text.Text = "Red Bacon Army"
    Dbutton.Visible = true
    teamchanged:FireServer()
end
script.Parent.background.RBA.MouseButton1Click:Connect(RBA)
function MP()
    P.TeamColor = game.Teams["Military police"].TeamColor
    text.Text = 'Moderation Depratment'
    Dbutton.Visible = true

end
script.Parent.background.MP.MouseButton1Click:Connect(MP)
function IB()
    P.TeamColor = game.Teams["Imperalist Bloxburg"].TeamColor
    text.Text = 'Imperalist Bloxburg'
    Dbutton.Visible = true  

end
script.Parent.background.IB.MouseButton1Click:Connect(IB)
function EO()
    P.TeamColor = game.Teams["Experimental Operations"].TeamColor
    text.Text = 'Experimental Operations'
    Dbutton.Visible = true

end
script.Parent.background.eo.MouseButton1Click:Connect(EO)
function Deploy()
    print('did it')
    script.Parent.Enabled = false
    script.Parent.Parent.MenuGui.Enabled = true
    P.Character.Humanoid.Health = 0
    Dbutton.Visible = false

end
Dbutton.MouseButton1Click:Connect(Deploy)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Use a RemoteEvent.

-- \\ Server script.

local RemoteEvent = Instance.new("RemoteEvent")
RemoteEvent.Name = "TeamChangeEvent"
RemoteEvent.Parent = game:GetService("ReplicatedStorage")

RemoteEvent.OnServerEvent:Connect(function(player, team)
    if not team or typeof(team) ~= "Instance" or not team:IsA("Team") then
        return error("Attempted to supply team arugment with non-team object.")
    end
    player.TeamColor = team.TeamColor
end)

-- \\ Client script.

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("TeamChangeEvent")

local function SEF()
    local Team = game:GetService("Teams")["Special Emergency Forces"]
    RemoteEvent:FireServer(Team)
    text.Text = Team.Name
end

0
It worked thank you I learned on how you need to use events if you want to fire something into the server it gave more context WindowsXPisathing 2 — 4y
0
@TheLuminet would I still use the MouseButoonClickEvent? WindowsXPisathing 2 — 4y
Ad

Answer this question