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

How can I transfer a value from one script to another?

Asked by 4 years ago

Hi there, I am creating a game that will give players a value "mins". I want to transfer this value to another script so that when the player has enough "mins", they can walk into a door and be teleported to another section of the game. How can I transfer this variable across from one script in the workspace to another script inside a part? Thanks a lot! (I'm happy to clarify if you aren't 100% on the question)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Remote events,

Instructions:

create a remote event in replicated storage, set its name to "RemoteEvent" then, learn from these scripts:

localscript in startergui

local value1 = 500

game.ReplicatedStorage.RemoteEvent:FireServer(value1) 

Above, value1 is being sent to whatever is received on the other end of the remote.

regular script in workspace

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(p,value1))
    -- parameters can be named anything but when transfering values, "p" will always be the player, its by default the first value.
    print(value1)
end)

Make sure that you use this method except use "mins" as value1 Hope this helped

Ad

Answer this question