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:
function onPlayerEntered(newPlayer) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local player = newPlayer mins = Instance.new("IntValue") mins.Name = "Minutes Riding" mins.Value = 0 mins.Parent = stats stats.Parent = newPlayer while true do mins.Value = mins.Value + 1 if mins.Value >= 60 and mins.Value < 120 then player.TeamColor = game.Teams["2nd Class"].TeamColor else if mins.Value >= 120 and mins.Value < 180 then player.TeamColor = game.Teams["1st Class"].TeamColor else if mins.Value >= 180 and mins.Value < 240 then player.TeamColor = game.Teams["Business Class"].TeamColor else if mins.Value >= 300 then player.TeamColor = game.Teams["Non-Stop Rider"].TeamColor wait(0.01) end end end end end end game.Players.ChildAdded:connect(onPlayerEntered)
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:
tele = script.Parent.Parent.TeleSettings.Position.Value lvl = 60 function onTouched(hit) player = game.Players:GetPlayerFromCharacter(hit.Parent) if hit.Parent:FindFirstChild("Humanoid") then if (This is where I would like the value to go) >= lvl then hit.Parent.Torso.CFrame = CFrame.new(tele) end end end script.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
Mostly to send information or functions, between Scripts or Between Local Scripts, we Use BindableEvents.
local be = script.Parent -- Define a simple function to connect -- to the custom event local function onEvent(...) print(...) end be.Event:Connect(onEvent) -- Fire the event be:Fire("Hello, world")