Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

OnServerInvoke Only Implemented on Server?

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

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

3 comments

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.

0

Ok, so you're new at this? I can give you a detailed explanation over skype.

0

Well not completely new anymore but yea i would appreciate an explanation please, I use discord my discord is lalelz#9877

This discussion is preserved as it was. New answers, comments, and votes are closed.