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

Why are my parameters all set to the local players' name?

Asked by 5 years ago

So I'm kind of new to RemoteFunctions and all of that stuff, so I'm trying to make a local script activate a function inside of a normal script to create teams based off of user input, but instead of my parameters having the correct values they are all assigned to the player? I've been trying to fix this for a considerably long time and I need some help. Here's some of my code

This is the LocalScript that sends a request to a RemoteFunction called "CreateTeamRequest"

GetStarted.GetStartedButton.MouseButton1Click:connect(function()
    local focus = Stuff.ChooseFocus.CompanyFocus.Text
    local color =                               BrickColor.new(GUI.LeCanvas.Tabs.Tab2.Customization.ColorViewer.ImageColor3)
    local name = Company.Text
    local children = GUI.LeCanvas.Tabs:GetChildren()
    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local createTeamRequest = ReplicatedStorage:WaitForChild("CreateTeamRequest")

    local newTeam = createTeamRequest:InvokeServer(name,color,focus,children,open,player)
end)

This is the script that accepts the request from the LocalScript and is suppose to create a team

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createTeamRequest = Instance.new("RemoteFunction")
createTeamRequest.Parent = ReplicatedStorage
createTeamRequest.Name = "CreateTeamRequest"

local function onCreateTeamRequested(teamname,color,focus,children,open,player)
    print("Creating team: Name, ",teamname," TeamColor, ",color)
    if not game.Teams:FindFirstChild(teamname) then
        local companyName = Instance.new("Team")
        companyName.Name = teamname.Text
        companyName.Parent = game.Teams
        companyName.TeamColor = color
        player.leaderstats["Company Focus"].Value = focus
        for i=1, #children do
            children[i]:Destroy()
        end
        player.Team = companyName
        companyName.AutoAssignable = false
        open.Text = ("Company Stats")
    end
end

createTeamRequest.OnServerInvoke = onCreateTeamRequested

Instead of giving the correct parameters to create the team it changes all my parameters i put in to the name of the user. Please help me figure this out as I am still very new to RemoteFunctions! Thx :D

1 answer

Log in to vote
0
Answered by
Mr_Pure 129
5 years ago

As far as InvokeServer functions go the first parameter will always be referred to as the localplayer, everything else will be your tuple.

--local script

local RemoteEvent = --Location of remote event


RemoteFunction:InvokeServer("Red", 3, true)



--Server script

local RemoteEvent = --Location of remote event

RemoteEvent.OnServerInvoke:connect(function(player, red, 3, true)

end)

so in your case the script is inferring that "teamname" is the player.

0
i dont quite get it,all my parameters are localplayer even though they're not suppose to be TheTurtleStudioYT 15 — 5y
0
Try changing "createTeamRequest.OnServerInvoke = onCreateTeamRequested" To createTeamRequest.OnServerInvoke:connect(onCreateTeamRequested) Mr_Pure 129 — 5y
0
nvm just had to reread it TheTurtleStudioYT 15 — 5y
Ad

Answer this question