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

How would i make a remote event with this script?

Asked by
262187 45
9 years ago

I have a gui that kicks a player, but i want to know who kicked the player so i tried using a local script but then i realized i can't kick on local scripts. I know little about remote events. Can anyone help?

Player = game:service'Players'.LocalPlayer

function click()
    if script.Parent.Parent.TextBox.Text == "" then
    else
    local Reason = script.Parent.Parent.KickReason.Text
    local Kicked =  script.Parent.Parent.TextBox.Text
    game.Workspace.Players:FindFirstChild(Kicked):Kick("You have been kicked, for Reason: "..Reason )
    print(Kicked.." has been kicked by "..Player" For reason: "..Reason)
    end
end
script.Parent.MouseButton1Down:connect(click)
0
Have you tried adding a function, where you must put your name in the GUI? It acts as a safety measure as well as a function.. TheHospitalDev 1134 — 9y
0
Yeah I thought of that, but it may not be that secure, for example someone can falsely put someone else name. 262187 45 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

I believe a RemoteFunction is what you're looking for. It allows you to execute server scripts within a local script.

Create a server script and put a RemoteFunction inside. Put that script in the script like this. (makes a lot of sense, lol.)

script.RemoteFunction.OnServerInvoke = function(player)
Player = game:service'Players'.LocalPlayer
script.Parent.MouseButton1Down:connect(function()
    if script.Parent.Parent.TextBox.Text == "" then
    else
        local Reason = script.Parent.Parent.KickReason.Text
        local Kicked =  script.Parent.Parent.TextBox.Text
        game.Workspace.Players:FindFirstChild(Kicked):Kick("You have been kicked for "..Reason)
        print(Kicked.." was kicked by "..Player.Name.. " for "..Reason)
        end
    end)
end

Then, in a local script, do this.

game.Workspace.Script.RemoteFunction:InvokeServer() --Already passes "player", so no need to do so again
Ad

Answer this question