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

How do I use a remote event in this script?

Asked by 5 years ago

It's a local script and I'm trying to insert a remote event for it to not be client sided

local cpsamount = 1 --how much cps given
local price = 50 --price of item

aot = 0
script.Parent.MouseButton1Click:connect(function()
    local bux = game.Players.LocalPlayer.leaderstats.Bux
    local button = script.Parent.Parent
    local cps = bux.Parent.Parent.Stats.Cps
    button.BackgroundColor3 = Color3.fromRGB(0,0,0)
    if bux.Value >= price then
        cps.Value = cps.Value + cpsamount
        aot = aot + 1
        bux.Value = bux.Value - price
        local sound = script.Parent.Parent.Parent.Sound
        sound:Play()
        local msg = game.ReplicatedStorage.MSG:clone()
        msg.Parent = game.Players.LocalPlayer.PlayerGui
        msg.TextBox:TweenPosition(UDim2.new(-0.015,0, -0.045,0), 'Out', 'Bounce', 1.5)
        wait(2.5)
        msg:Destroy()
    else
        print("Not enough")
    end
end)
0
Try doing it yourself Shawnyg 4330 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

In the future, check the wiki before asking here. Anyways, to answer your question, start by going to ReplicatedStorage and inserting a RemoteEvent.

You can have a script do code when this event is triggered by a local script using the "OnServerEvent" event of the remote itself. (Basically, the same way you would use a Touched event, but with a different event in place of it)

In the LocalScript, you can fire the remote event by using a built-in function of the event,

game.ServerStorage.RemoteEvent:FireServer()

As an added tip, you can use the local script to send data along with the trigger by having it as an argument. For example,

game.ServerStorage.RemoteEvent:FireServer(Vector3.new(15, 1, 0))

If this answered your question, please accept it. You can find more info here as well. wiki.roblox.com/index.php?title=Remote_Functions_%26_Events

Ad

Answer this question