ServerRemote affects all clients [PROBLEM]

The problem: I created a function inside a server script (in ServerScriptService) that gives the player 10 points. The function is fired by a remote that’s triggered from a local script example - (player use tool … event fired). The problem is that then the event is fired, not only the player gets their points, but also all the other players in the session.

Server script:

moneyPay.OnServerEvent:Connect(function(plr)
	
		money.Value = money.Value + 1 * level.Value
		
	end)

Local script:

— some text

moneyPay:FireServer()

— some text

Any solutions?

Make sure to define which player you are giving the money to

plr.Money.Value = money.Value+1*level.Value

Hope that works!

I made a remote that gives players money, I think you can adapt it

—Server
Event.OnServerEvent:Connect(function(player, money, amount, level)
    money.Value = money.Value + amount * level.Value
end)

—Client
Event:FireServer(yourCurrency,theAmount,theLevel)

I think that should work :slight_smile:

Roblox recently added the option to do
plr.Money.Value += 1*level.Value

just thought i would share because i think its pretty cool

Just going to point out that doing things like that is very wrong (remote securing wise). You should NEVER trust the client. The amount and level both should be decided by the server, not the by the client. You most probably shouldn’t even create a remote event that just adds money without any checks, the exploiter can simply fire it again and again.

1 Like

The local script - (extension)

    local function GrappleToPosition(position)
    	-- make sure the character exists
    	if not character then
    		return
    	end
    	
    	-- dont allow grappling while already grappling
    	if grappling then
    		return
    	end
    	
    	-- fire remote so the server can replicate the effect
    	GrappleRemote:FireServer(position)
    	moneyPay:FireServer() ---- **Here** ----
    	print(position)
    	grappling = true
    	
    	-- play the grapple effect on the client
    	GrappleEffect:Play(character, position, Grapple.CastTime, Grapple.TravelTime)
    	
    	-- ez camera tween for more impact
    	local cameraInfo = TweenInfo.new((Grapple.CastTime + Grapple.TravelTime - (game.Players.LocalPlayer.leaderstats.Speed.Value / 100)) / 2, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, true)
    	local cameraTween = Services.TweenService:Create(Camera, cameraInfo, {FieldOfView = Camera.FieldOfView + 30})
    	cameraTween:Play()
    	
    	-- cast
    	-- play the cast animation
    	animations.Cast:Play(0.1, 1, 1/(Grapple.CastTime * 2))
    	
    	-- tween the character into position, keeping them floating in the air
    	local castInfo = TweenInfo.new(Grapple.CastTime, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
    	local castTween = Services.TweenService:Create(root, castInfo, {CFrame = CFrame.new(root.Position, position)})
    	
    	castTween:Play()
    	castTween.Completed:Wait()
    	
    	-- travel
    	-- calculate the landing position and tween to it
    	local direction = (position - root.Position)
    	local travelCFrame = CFrame.new(position + Vector3.new(0, 4, 0), position + Vector3.new(direction.X, 4, direction.Z))
    	
    	local travelInfo = TweenInfo.new(Grapple.TravelTime, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
    	local travelTween = Services.TweenService:Create(root, travelInfo, {CFrame = travelCFrame})
    	
    	travelTween:Play()
    	travelTween.Completed:Wait()
    	
    	-- land
    	-- switch to getting up in case we tripped somehow
    	humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
    	grappling = false
    end

The game: 95% DISCOUNT!!! l Grapple Hook Simulator - Roblox

Try that:

moneyPay.OnServerEvent:Connect(function(plr)
     local money = plr.Money --change it 
     money.Value = money.Value + 1 *plr.Level.Value
		
end)

Now - nobody gets their points.

I found the solution - thanks to all :smiley:

I highly recommend to not have a remote that directly alters player money, as exploiters can easily give themselves any amount of money.

Instead, for interactions tell the server that a client as performed an interaction, say for example they’ve sold an item in a shop. Verify that the player is allowed to sell that item, that the item exists in that player’s inventory, and check the value of that item all on the server and change the money from there.

1 Like