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 in a simple way?

Asked by 5 years ago

I am new to Lua coding, I have a fair understanding of python which I can see some similarities between the two and I would like some help to create a mechanic in my game.

I would like to transfer the value "mins" from this script which counts how many minutes the player has been in the game:

01function onPlayerEntered(newPlayer)
02 
03    local stats = Instance.new("IntValue")
04    stats.Name = "leaderstats"
05    local player = newPlayer
06    mins = Instance.new("IntValue")
07 
08    mins.Name = "Minutes Riding"
09    mins.Value = 0
10 
11 
12    mins.Parent = stats
13 
14    stats.Parent = newPlayer
15 
View all 37 lines...

into this script so that I can enable players who have played a certain time to be able to use a teleport door to help them reach the next stage:

01tele = script.Parent.Parent.TeleSettings.Position.Value
02 
03lvl = 60
04 
05 
06function onTouched(hit)
07 
08player = game.Players:GetPlayerFromCharacter(hit.Parent)
09 
10    if hit.Parent:FindFirstChild("Humanoid") then
11 
12        if (This is where I would like the value to go) >= lvl then
13 
14            hit.Parent.Torso.CFrame = CFrame.new(tele)
15 
16        end
17    end
18end
19 
20script.Parent.Touched:connect(onTouched)

I'm not 100% on things such as remote events and the difference in script types, but I am happy to give all options a go if I can understand them! Thanks a lot

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Mostly to send information or functions, between Scripts or Between Local Scripts, we Use BindableEvents.

01local be = script.Parent
02 
03-- Define a simple function to connect
04-- to the custom event
05local function onEvent(...)
06    print(...)
07end
08be.Event:Connect(onEvent)
09 
10-- Fire the event
11be:Fire("Hello, world")
Ad

Answer this question