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 5 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 5 years ago
Edited 5 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

1local value1 = 500
2 
3game.ReplicatedStorage.RemoteEvent:FireServer(value1)

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

regular script in workspace

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

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

Ad

Answer this question