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 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?
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)
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?
--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.