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

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

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

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

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