Change A Team's Cash/Point Value From A Gui?

  1. What do you want to achieve?

I want to make a Gui that changes an entire teams Cash/Point Value
gui4

I have already made this Gui work for certain players with the help of the dev forum, but now I want to update it so you can add to a whole team’s cash/point value

  1. What is the issue?

I am having a lot of trouble doing this and I just don’t think I am going in the right direction.

  1. What solutions have you tried so far?

I have Manipulated my Main Value script to try and add a team part, I have made a 2nd RemoteEvent,
I have even changed the script inside of the Give button but it just won’t work. Which is why I decided to make this post, and here is my original post (that was solved) on trying to make it players only: Change A Player's Cash/Point Value From A Gui

Anyways, thanks for reading and if you can help please do so, I will take any advice lol :slight_smile:

1 Like

Could you try using :GetPlayers(), then write a IF statement regarding if the player is apart of the team, and if so give them the commends. I’m not the best at scripting but I might be able to help with scripting.

1 Like

Yea my code is actually like that, and I have two scripts in ServerScriptService that check if the events have been fired one checks if only the Player Name part was used and one checks for the team

--team only script
game.ReplicatedStorage.TeamEvent.OnServerEvent:Connect(function(player, team, Values)
	for i = 1, #player do
		if #player.Team.Name == ""..team then
			local PlayerToGive = game.Players:FindFirstChild(Values[2])
			PlayerToGive.leaderstats.Commends.Value += Values[1]
		end
	end
end)

--Player only script (works)
game.ReplicatedStorage.AdminEvent.OnServerEvent:Connect(function(player, Values)

local PlayerToGive = game.Players:FindFirstChild(Values[2])

PlayerToGive.leaderstats.Commends.Value += Values[1]

end)

Could you show the script that fires the remote event?

Sure!

function onClick()
	local FindName = script.Parent.Parent.PlayerName.Text
	local FindTeam = script.Parent.Parent.TeamName.Text
	script.Parent.Parent.CurrentPlayer.Value = tostring(FindName)
	script.Parent.Parent.CurrentTeam.Value = tostring(FindTeam)
	local FindAmount = script.Parent.Parent.AmountOfPoints.Text
	script.Parent.Parent.Points.Value = tonumber(FindAmount)
	local team = script.Parent.Parent.CurrentTeam.Value
	
	local Values = {
		script.Parent.Parent.Points.Value,
		script.Parent.Parent.CurrentPlayer.Value
	}
	
	game.ReplicatedStorage.AdminEvent:FireServer(Values) --This is a remote event I created which is transferring the table of values.
	game.ReplicatedStorage.TeamEvent:FireServer(team, Values)
end

script.Parent.MouseButton1Click:Connect(onClick)

Could you try using this method? I haven’t tested it but it might work. ( I didn’t write this in studio so its messy )

  Players = game:GetService("Players")
    game.ReplicatedStorage.TeamEvent.OnServerEvent:Connect(function(player, team, Values)

    for i, player in pairs(Players:GetPlayers()) do
          if player.Team == team then
                 --give commends
          end
    end 

    end)

Ok, I will try it 30 characters

Ok I tried it but it didn’t work and I know why, When I put in a team and leave the “Player Name” blank it says in Output “ServerScriptService.Commend System Giver:3: attempt to index nil with ‘leaderstats’)”
because I there was nothing in the Textbox, Idk what to do about that. (at least that’s why I think it happened) Code:

Players = game:GetService("Players")
  game.ReplicatedStorage.TeamEvent.OnServerEvent:Connect(function(player, team, Values)

  for i, player in pairs(Players:GetPlayers()) do
        if player.Team == team then
              Players.leaderstats.Commends.Value += Values[1]
          end
    end 

end)

in line 6 try replacing “Players” with player.

1 Like

Same error “ServerScriptService.Commend System Giver:3: attempt to index nil with ‘leaderstats’”
But I added it because it will probably fix some other bug or something

1 Like

Could you play-test the game and show me the childs of your player.
Example:

image

1 Like

The syntax is a bit messed up, how about you try changing

game.ReplicatedStorage.TeamEvent.OnServerEvent:Connect(function(player, team, Values)

to

game.ReplicatedStorage.TeamEvent.OnServerEvent:Connect(function(plr, team, Values)

It might have been confusing the script into picking out the wrong variable.

2 Likes

I highlighted the Give Gui

Players = game:GetService("Players")
  game.ReplicatedStorage.TeamEvent.OnServerEvent:Connect(function(plr, team, Values)

  for i, player in pairs(Players:GetPlayers()) do
        if player.TeamColor == (Place the team's color here) then
              players.leaderstats.Commends.Value = players.leaderstats.Commends.Value + 1
          end
    end 

end)

I believe this should work.

2 Likes

Thanks, but I don’t want the script to only do one team but do it for the team you put in the textbox

btw I have to leave and I will be back later here is a download file of the gui if it helps while im gone

Baseplate.rbxl (31.2 KB)

1 Like

if player.TeamColor == (Place the team’s color here)

Simply change “player.TeamColor” to “player.Team.Name” add the parameter ‘team’ behind the == and make it pass on the team name which you want to change the values of.

2 Likes

It’s been a long time since I last replied here, but I think that the error comes from the give money to a single-player script rather than the give money to a entire team-script. Add money to the team and check if the if the team script added the commends by checking “Folder” > “Commends” in the explorer ( Example below)


image


Sorry for not replying for so long, god bless!

2 Likes