Get a certain line of code and beyond using another script?

Hi

I was wondering If it were possible to get a certain line of code from another script? Like this:

local serverScript = game:GetService("ServerScriptService")
local main = serverScript:WaitForChild("MainScript")
if 4+4 == true then
mainScript.Line44 == true

I have no idea if these sort of codes exist, so don’t say that I am noob :wink: I just want to know If it were possible to run an event in another code, using another script. If it is possible, how would I run the lines after line44 for example?

2 Likes

You can use bindableEvent to call a function in another script.

Making a moduleScript and then including it from where you want to use it is also possible.

No you would have to create a plugin to get a certain line, since only plugins and command bar can read the source of scripts. But that seems to be out of the scope of this topic, you might as well look into modules and/or bindables since they allow for communication between scripts

What exactly are you trying to achieve with this? If you’re looking for a better way of storing certain variables to go through multiple scripts you could use _G to pass through (of corse you’d need to use it wisely as it shouldn’t be your dependent)

I am trying to make it so when the player is in a certain place, the game ends and a certain line in my Main Script runs.

I’m not sure i’m getting what you’re trying to say. Could you just use a function within your module to run this line?

If you could I’d help to supply this line you’re trying to run.

So, when the player touches a part, the Status changes and everyone “resets”, therefore ending the game. However, I am unsure on how to do this.

Can’t you just run the resetting logic when a player touches the part? I don’t see why you would want to jump to a specific line in your script when you can just run the logic in your Touched listener?

Have you thought of using RemoteEvents / RemoteFunctions. If you have, then what exactly is your problem.

If you haven’t used them then here is some documentary for it:

With how you worded it it seems like the server to client event would do.

Adding onto what @incapaxx said, You could make a touch listener and fire an event to update everything.

1 Like

What is this status? A string or a number? But you need for this Values

It is a string value, located in Replicated Storage

1 Like

@Crrustyy:

--This serverscript add all what you need for each client
local RS = game.ReplicatedStorage
game.Players.PlayerAdded:Connect(function(player) --If a new Player enter in the game
    --Add a folder for saving Stats and other things (customize this)
    local Folder = Instance.new("Folder")
    Folder.Parent = RS
    Folder.Name = player.Name.."'s Folder"

    --Configure your Stats String Value
    local Stats = Instance.new("StringValue")
    Stats.Parent = Folder
    Stats.Name = "Stats"
    if gameIsPlaying then --Its your game system, customize this. gameIsPlaying is a boolean you need to create youself (P.S.: ServerSide else it dont work).
        Stats.Value = "On"
    else
        Stats.Value = "Off"
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    RS[player.Name.."'s Folder"]:Destroy()
end)
--Now this is in your Part (ServerScript, alias Script). Before you start think to insert a RemoteEvent in the location of your choice (i choice Replicated Storage)
local Part = script.Parent
local RS = game.ReplicatedStorage
local RE = RS.RemoteEvent --Customize this to indicate your RemoteEvent

Part.Touched:Connect(function(param)
    RemoteEvent:FireAllClients("Off")
end)

--Now, finally, your ClientScript
local Player = game.Players.LocalPlayer
local RS = game.ReplicatedStorage
local Stats = RS[Player.Name.."'s Folder"]:WaitForChild("Stats")
local RE = RS.RemoteEvent

RE.OnClientEvent:Connect(function(NewStats)
    Stats.Value = NewStats
    Player.Character.Humanoid:TakeDamage(100)
end)

As the others say: You need to learn the RobloxNetwork system, this include the Remote Events/Functions. I know you are new, but if you dont know this, you cant do anything. See the Wiki for more know, it really will help you.

You can get the Script’s source and change it. However, it works only with plugins or the command bar.

@TheTurtleMaster_2, what is a script source? I already have see this GUI parameter in a script, but never understanded…

A script’s source is it’s code transformed into a string.

like:

The script’s code:

print("Hello World!")

The script’s source:

print("Hello World!")
1 Like