How to remove points from another players leaderstats?

I recently added an automatic promotion system to my game. Meaning when a player plays for 30 minutes for example, they get promoted up 1 rank. However, there’s a flaw with this. If they get demoted and they have the points required for a promotion, it automatically ranks them back. So I wanted to add an experience remover where my High Ranks can input how much experience they want to remove from them. This is the script I have so far (has player,name, send, money because I just copied the format from the citation system I developed bc lazy.

game.ReplicatedStorage.Demote.OnServerEvent:Connect(function(player, name, send, money)


            send.leaderstats["Experience"].Value = send.leaderstats["Experience"].Value - money



end)

Money is the “experience” input value to be removed.

If anybody could help me with this, you’d be a life saver, I’ve been messing around with this script for 30 minutes with no promising outcome.(and yes, I plan on adding security to the remote event - there’s just no security as of now due to testing it in stuido.)

Thanks!

1 Like

If this is of any help I’ve also tried this

game.ReplicatedStorage.Demote.OnServerEvent:Connect(function(player, name, send, money)


           game.Players:FindFirstChild(send).Name.leaderstats["Experience"].Value = game.Players:FindFirstChild(send).Name.leaderstats["Experience"].Value - money



end)
1 Like

Are there any errors in the output?

1 Like

None at all, it fires as if it works - but nothing is done to the leaderstats.

1 Like

Try adding a print before and after it changes the leaderstats and tell me if they both print.

1 Like

you should be doing

plr.leadesrstats.Experience.Value = plr.leadesrstats.Experience.Value - 1

Unless the leaderstats aren’t parented to the player (I doubt it would be a leader stat then), if you don’t change the value of the leaderstat parented to the player, it won’t change the leaderstat.

1 Like

Just for note (send) is the player to have leaderstats removed. It’s not removing the own player’s stats - but the person who’s inputted in the GUI that fires the event upon the demotion button being pressed.

name = player sending (along with player = player sending)
send = player being demoted
money = amount of experience being removed from player. I’ll try that - but I believe that’s a line I’ve already tried.

1 Like

What is you client side script which fires the remote event?

1 Like
game.ReplicatedStorage.Demote.OnServerEvent:Connect(function(player,name, send, money)
           print(1)
            send.leaderstats.Experience.Value =  send.leaderstats.Experience.Value - money
           print(2)
end)

Try that and send me the output after

1 Like

For further reference, here is the localscript located in the GUI.

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()

	local money = script.Parent.Parent.amount.Value
	local send = script.Parent.Parent.username.Value
	local name = script.Parent.Parent.name.Value
	if game.Players:FindFirstChild(send) then
	game.ReplicatedStorage.Demote:FireServer(name, send, money)
	script.Parent.Parent.userna.Text = ''
	script.Parent.Parent.TextBox.Text = ''

	end
	end)

and here is the server side script

game.ReplicatedStorage.Demote.OnServerEvent:Connect(function(player, name, send, money)

print("Firing event")
           game.Players:FindFirstChild(send).Name.leaderstats["Experience"].Value = game.Players:FindFirstChild(send).Name.leaderstats["Experience"].Value - money
print("It worked!")


end)

@profak When I tried the print, it didn’t seem to make either of them work. I’m still rather new to Remote Event’s, even though I’ve done about 5 other features like this. Not sure if it’s the remote event messing up, or the line of code itself.

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()

	local money = script.Parent.Parent.amount.Value
	local send = script.Parent.Parent.username.Value
	local name = script.Parent.Parent.name.Value
	print(send)
	if game.Players:FindFirstChild(send) then
	     print("W1")
	      game.ReplicatedStorage.Demote:FireServer(name, send, money)
	      script.Parent.Parent.userna.Text = ''
	      script.Parent.Parent.TextBox.Text = ''
	     print("W2")
	end
end)

Tell me what that prints.

Screenshot_1

Also if this is of any help…

This is located in the main script system for my game.

local ranktime = Instance.new("IntValue")
ranktime.Name = "Experience"
ranktime.Parent = leaderstat
game.ReplicatedStorage.Demote.OnServerEvent:Connect(function(player,name, send, money)
           print(1)
            send.leaderstats.Experience.Value =  send.leaderstats.Experience.Value - money
           print(2)
end)

have you tried this?

Screenshot_698

It does that, as if it’s not even connecting to the RemoteEvent.

Where is your sever script located? It won’t run if it isn’t a descendant of the ServerScriptService, the Workspace or a Backpack

Where is your server script and can you send the full code for the server script?

Where should it be located then?

I have it placed in ServerScriptStorage because that’s where I’ve had the Citation and Donation GUI’s Server Script located which they worked just fine, no issues at all.

And this is the full Server Script

game.ReplicatedStorage.Demote.OnServerEvent:Connect(function(player, name, send, money)
           print(1)
            send.leaderstats.Experience.Value =  send.leaderstats.Experience.Value - money
           print(2)
end)

Try printing at the beginning of your script, to see if it is even running, scripts in the ServerScriptService do run, unless their Disabled property is set to true

Put your server scripts in ServerScriptService