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

OnServerInvoke Only Implemented on Server?

Asked by
Laxely 3
6 years ago

Hi, I have a local script inside the Starter Pack that has a server script with a remote function inside it.

The function works perfectly but the problem is that nobody else can see the actual script except the client.

I've tried OnServerInvoke but that comes up with 'OnServerInvoke can only be implemented by server'

I know I could just use a server side script and make it fire the function in the Backpack but I want the function to work like a local script in the backpack and fire every time the player respawns.

Any sort of help is always appreciated.

1 answer

Log in to vote
0
Answered by
Bellyrium 310 Moderation Voter
6 years ago
Edited 6 years ago

On serverInvoke requires a non local script. A local script Invokes the server and the server through a normal script listens for it.

so you would make the event and have event.ServerInvoke:connect(function) on the server, and have a local script that finds the event and Invokes it with a variable.

-- Script

local Players = game:GetService("Players")

local welcomePlayerEvent = Instance.new("RemoteEvent")
welcomePlayerEvent.Parent = game.ReplicatedStorage
welcomePlayerEvent.Name = "WelcomePlayerEvent"

local function onPlayerAdded(player)
    welcomePlayerEvent:FireClient(player)
end

Players.PlayerAdded:Connect(onPlayerAdded)
--LocalScript

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local player = Players.LocalPlayer
local welcomePlayerEvent = ReplicatedStorage:WaitForChild("WelcomePlayerEvent")
local playerGui = player:WaitForChild("PlayerGui")

local welcomeScreen = Instance.new("ScreenGui")
welcomeScreen.Parent = playerGui
local welcomeMessage = Instance.new("TextLabel")
welcomeMessage.Size = UDim2.new(0, 200, 0, 50)
welcomeMessage.Parent = welcomeScreen
welcomeMessage.Visible = false
welcomeMessage.Text = "Welcome to the game!"

local function onWelcomePlayerFired()
    welcomeMessage.Visible = true
    wait(3)
    welcomeMessage.Visible = false
end

welcomePlayerEvent.OnClientEvent:Connect(onWelcomePlayerFired)

right from the wiki -http://wiki.roblox.com/index.php?title=Remote_Events_and_Functions

0
Sorry, I said I wanted it so the function was like a local script in the starterpack. This would only execute the function once when the player joins. I want it so it works like it's inside the starterpack. Laxely 3 — 6y
0
Ok, so you're new at this? I can give you a detailed explanation over skype. Bellyrium 310 — 6y
0
Well not completely new anymore but yea i would appreciate an explanation please, I use discord my discord is lalelz#9877 Laxely 3 — 6y
Ad

Answer this question