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

How do I fire server from a script?

Asked by
Nickelz 37
5 years ago
Edited 5 years ago

Not sure how to explain this, but here it goes.

I have a remote event in replicated storage that, when fired, it gets the player, amount of money to handle, whether to add or subtract said amount, and a code. so when fired from a local script it looks like this (I changed the password):

game.ReplicatedStorage.RemoteEvents.ManageMoney:FireServer(cost,"add","password123")

then, on a script inside ServerScriptService, it handles it like this:

function manage_money(player,amount,operation,pass)
    local name = player.Name
    local plr = game.Players:FindFirstChild(name)
    if pass == "password123" then
        if operation == "add" then
            for i = 1,amount/5 do 
            wait(0.01)
            plr.Settings.Money.Value = plr.Settings.Money.Value+5
            game.SoundService.coins_pay:Play()
        end
        elseif operation == "remove" then
            for i = 1,amount/5 do
                wait(0.01)
                plr.Settings.Money.Value = plr.Settings.Money.Value-5
            end
        end
        elseif pass ~= "password123" then
            if plr:IsA("Player") then
                plr.Settings.HasExploited.Value = plr.Settings.HasExploited.Value+1
                    plr:Kick("You have been kicked for exploiting.")
            end
    end

            end

it all works well for me however confusing it is to any other people looking at my code, but then I encountered a problem: I wanted to give players money for touching a pad at the end of a practice obby, but I cannot do this without a localscript!

please help me with this and tell me if I need to clarify anything :)

0
You don't need a localscript to do this, I don't think. But I don't know exactly how you are doing this. Optikk 499 — 5y
0
when I touch a pad, I want it to fire an event including at the very least just the amount and password, then the server adds the amount to the local player Nickelz 37 — 5y
0
I still don't see why you need a localscript. A server script can handle both touched events and changing a player's point count. Optikk 499 — 5y
0
can you please explain how? I only started to understand remote events 2 days ago literally Nickelz 37 — 5y
View all comments (4 more)
0
i think what you're looking for is FireClient(). but also what optikk said. DinozCreates 1070 — 5y
0
What I did now was: when the pad is touched, it fires client with amount,operation,code. then, from a localscript, onclientevent, I took amount,operation,code, and fired server from there. but it said "Unable to cast value to object". I feel like this should be a lot more simple... Nickelz 37 — 5y
0
Just call the manage_money function like this: manage_money(plr, 100, "add", "password123") from the Touched handler??? Also you realize your password security is so bad that it's almost like if there was no security? Amiaa16 3227 — 5y
0
wow! thanks, I thought I did not have to mention the player when firing the client, but wdym about my security? is there a way to improve it? Nickelz 37 — 5y

Answer this question