Why is this script not giving errors, yet not doing nothing?

This is a code to turn currency into lives, or do some other features that could be useful for console commands or debugging

This script is not doing anything for some reason, I checked and all the functions exist and all, and this is a normal script and not a LocalScript

game.ReplicatedStorage.SpecialEvents.GetSeeds.OnServerEvent:Connect(function(player, amount)

player.PlayerInfo.Seeds.Value = player.PlayerInfo.Seeds.Value + amount

end)

game.ReplicatedStorage.SpecialEvents.GetLives.OnServerEvent:Connect(function(player, amount)

player.PlayerInfo.Lives.Value = player.PlayerInfo.Lives.Value + amount

end)

game.ReplicatedStorage.SpecialEvents.SetSeeds.OnServerEvent:Connect(function(player, amount)

player.PlayerInfo.Seeds.Value = amount

end)

game.ReplicatedStorage.SpecialEvents.SetLives.OnServerEvent:Connect(function(player, amount)

player.PlayerInfo.Lives.Value = amount

end)

game.ReplicatedStorage.SpecialEvents.RemoveSeeds.OnServerEvent:Connect(function(player, amount)

player.PlayerInfo.Seeds.Value = player.PlayerInfo.Seeds.Value - amount

end)

game.ReplicatedStorage.SpecialEvents.RemoveLives.OnServerEvent:Connect(function(player, amount)

player.PlayerInfo.Lives.Value = player.PlayerInfo.Lives.Value - amount

end)

And I call these functions trough RemoteEvents from a LocalScript like this:

game.ReplicatedStorage.SpecialEvents.GetLives:FireServer(plr, 1)
game.ReplicatedStorage.SpecialEvents.SetLives:FireServer(plr, 0)

I have no Idea why this is not working, please send help.

1 Like

You don’t need the “player” argument on the client-side, only the server-side I believe.

2 Likes

How will I specify that I want to Identify the player’s currency without having an argument of them in the first place?

Roblox does that automatically

In addition to what @NineFineMuscadines said, you really shouldn’t let the client tell the server how many lives to set/get

https://developer.roblox.com/en-us/api-reference/class/RemoteEvent

image

2 Likes

How will I get/set lives without one or the other?

  1. I cannot tell the client to change how many lives, It will just not work since it’s only the user who sees it.

  2. I cannot have the server Identify the stats of the player, I cannot use LocalPlayer in a normal Script

Allowing the client to tell the server what to do just opens the door for exploiters to abuse it

-- client
RemoteEvent:FireServer()
-- server
RemoteEvent.OnServerEvent:Connect(function(playerWhoFired) -- roblox passes the player who fired, you don't need to do that
  -- do stuff
end)

Does the system you’re using depend on the client? Or can some of it be moved to the server?

If you’re setting the Values on the client side, that’s probably why it isn’t working
You’d need to do it on the server instead, it should work regardless?

I have no Idea if it can be even moved to a normal script, but I do not know if it really depends on the client, you really gotta put up a scenario for my three little brain cells bouncing in my head.

Ok so, what does the system do? Does the player click something? Like an object?

The player must achieve a certain amount of seeds (coins) (100 or more in this case) to get an extra 1-up, just like Mario.

Ok, so, the client can just fire the FireServer event and the server sets the extra one up from there

-- client

if condition then
   RemoteEvent:FireServer()
end
-- server

RemoteEvent.OnServerEvent:Connect(function(player)
   player.PlayerInfo.Lives.Value += 1 -- adds 1 life
end)

That is exactly what I am implying! and I added other events just in case it’s required.

An alternative would be to have the server detect it with no remotes

game.Players.PlayerAdded:Connect(function(player)
   local info = player:WaitForChild("PlayerInfo")

   info.Seeds:GetPropertyChangedSignal("Value"):Connect(function() -- detect when the "seeds" value property has been changed
       if info.Seeds.Value % 100 == 0 then -- checks if the player has gotten 100 (200, 300 etc) coins
          info.Lives.Value += 1 -- add 1 life
       end
   end)
end)
2 Likes

This actually worked! Now nobody will be cheating their lives and seeds.