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

Server Send Values to client with RemoteEvent or other way?

Asked by
ksony 54
6 years ago
Edited 6 years ago

I have an intvalue saved in serverStorage, how can I do it so that it is constantly sending its value to a local intalue with remote events, if it is not possible with remote events, what other form is there? I can not save it in replicated storage

0
You could have the int value in ReplicatedStorage. User#25115 0 — 6y
0
I can not save it in replicated storage ksony 54 — 6y

2 answers

Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
6 years ago
Edited 6 years ago

Using RemoteEvents:

Create RemoteEvent in ReplicatedStorage

Server(ServerScript/Script)

-- ServerScriptService
local event = game.ReplicatedStorage.Event -- Event location

local value = 100

event:FireAllClients(value) -- Send the value to all clients
--[[
Also for send for one client use this:
event:FireClient(player,value)
    You need to specified player in the FireClient
]]

Client(LocalScript)

-- StarterGui
local event = game.ReplicatedStorage.Event -- Event location

event.OnClientEvent:Connect(function(value) -- Detect event and get argument / you dont need to put player argument here. only arguments send by server.
    print("I got value: " .. tostring(value))
end)

Also if you dont like RemoteEvents you can use a IntValue,StrintValue in ReplicatedStorage

Create a Value in ReplicatedStorage

Server(ServerScript/Script)

-- ServerScriptService
 -- Change value
local value = game.ReplicatedStorage.MyValue -- In this example i used a StringValue / location of your value

value.Value = "Hello!" -- Change the value of your Value

Client(LocalScript)

-- StarterGui
 -- Detect change

local value = game.ReplicatedStorage.MyValue -- location of your value

value.Changed:Connect(function() -- Detect if anything in value changed(name,value...).
    print("I got value: " .. tostring(value.Value))
end)

What Changed make?

  • Detect if anything in object changed

What Event.OnClientEvent make?

  • This is used to retrieve remote events fired by the server and intended for the client.

What Event:FireClient make?

  • Fire event for the specified player.

What Event:FireAllClients make?

  • Fire the event for all players in game

This is in wiki page

Hope it helped :)

Wiki pages

Changed

0
:GetPropertyChangedSignal in your case is pointless. Use the Changed event User#24403 69 — 6y
0
Edited yHasteeD 1819 — 6y
0
I say that because for ValueBase instances (IntValue, RayValue, etc) Changed is modified to fire only for the Value property User#24403 69 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

What I would do is have a remote event in ReplicatedStorage and use a script to retrieve the value, and then fire the remote event to the client with the value as a parameter, and then use a local script to listen to this value and change the local IntValue

-- Script in ServerScriptStorage
local Event = game:GetService("ReplicatedStorage").RemoteEvent -- The event in ReplicatedStorage
game:GetService("Players").PlayerAdded:Connect(function(player) -- This code starts running when a player joins the game
    while true do
        local value = game:GetService("ServerStorage").Value.Value -- The value of your IntValue in ServerStorage
        Event:FireClient(player, value) -- The value is sent to the client as a parameter when the event is fired
        wait(60) -- Makes the code run every 60 seconds (1 minute)
    end
end)
-- Local Script
local Event = game:GetService("ReplicatedStorage").RemoteEvent -- The event in ReplicatedStorage (The client can also access this)
Event.OnClientEvent:Connect(function(value) -- This runs when the event is fired, value is the parameter from above, the IntValue's value in ServerStorage
    script.Parent:WaitForChild("Value").Value = value -- The script.Parent:WaitForChild("Value").Value can be changed to wherever your local value is
end)

If you need any more help or I made a mistake, feel free to let me know

Answer this question