How do i make a value transfer to another script

Hello, i am very new to coding and very new to scripting on Roblox. So, i want to be able to press a button and have that output a number 1, in another script i want it to be able to read that number and compare it to 1.

I want it to function like this in theory.

Script 1

script.Parent.ClickDetector.MouseClick:Connect(function()
	shared.a = 1
end)

Script 2

local numbera = shared.a
 If numbera == 1 then
print(numbera)
end

(i know this doesnt work but something like this)

i tried using the intvalues too but they wont update to the second script when i input a value in to the first script

I would appreciate any advice on how to make something like this work.

Try either a RemoteEvent or a BindableEvent. Remote events let you send variables from the client to the server / the server to the client, while BindableEvents let you send variables from server script to server script / client script to client script.

1 Like

If you did use int values, then there is a chance u didnt use them right, that can be if the script runs immideatly or if script 1 is a local script. For this to work in a local script maybe use remote events like the guy above me told you or use the .Changed event in the second script. This will fire every time one of the int values property changed. Do like

local numbera = shared.a -- assuming this is a int value
numbera.Changed:Connect(function()
if numbera.Value == 1 then
print(numbera.Value)
end
end

i hope this helped you

2 Likes

If both scripts are local scripts you can use _G

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.