Why isn’t my script working? I’m calling a module and it runs perfectly, but when the player who called it leaves, the script just stops functioning. Does the thread break when the caller leaves? Is this a property of modules? I’m not very experienced with them. I also tried using ‘_G’. Is this something I’ve never seen before?
If I’m understanding this right, then everything that is run on the ModuleScript will be run at a local level, meaning that its scripts aren’t serverside. As a result, if the player who called it leaves, it would break because everything is being run locally and not on the server.
it’s run on a modulescript that’s on serverscriptservice
Could you elaborate on what you mean by “when the player who called it”?
well a player’s server script calls the function, and leaves while the function that he called is running on a module, then the script just stops
this is the script, runs just fine if the player stays while the module is running
module.RestoreAnchor=function(Person,Time)
spawn(function()
local Player=Person
if game.Players:GetPlayerFromCharacter(Person) then
game.Players:GetPlayerFromCharacter(Person).RagDolled.Value=true
Player=game.Players:GetPlayerFromCharacter(Person)
elseif game.Players:GetPlayerFromCharacter(Person)==nil and Person:FindFirstChild(“RagDolled”) then
Person.RagDolled.Value=true
end
local Character=Person
local Tab={}
for i,v in next, Character.Humanoid:GetPlayingAnimationTracks() do
if v.Animation.Name==“Remove” or v.Animation.Name==“Anim8” then
v:Stop()
end
end
local bv=Instance.new(“BodyVelocity”)
bv.Velocity=Person.HumanoidRootPart.CFrame.lookVector*-30
bv.MaxForce=Vector3.new(1,1,1)*math.huge
bv.Name=“RagDollBV”
bv.Parent=Person.HumanoidRootPart
for i,v in next, Character.Torso:GetChildren() do
if v.Name==“Neck” or v.Name==“Left Hip” or v.Name==“Right Hip” or v.Name==“Right Shoulder” or v.Name==“Left Shoulder” then
table.insert(Tab,v)
v.Parent=game.ServerStorage.Joints
end
end
game.Debris:AddItem(bv,0.25)
Person.Humanoid.PlatformStand=true
Person.Humanoid.Sit=true
if Time==nil then
Time=1
end
wait(Time)
Person.Humanoid.PlatformStand=false
if game.Players:GetPlayerFromCharacter(Person) then
game.Players:GetPlayerFromCharacter(Person).RagDolled.Value=false
else
Person.RagDolled.Value=false
end
Person.Humanoid.Jump=true
if Person.LocalTime.Value==true then
until Person.LocalTime.Value==false
end
for i,v in next, Tab do
v.Parent=Character.Torso
end
end)
end
From what I’m understanding, you’re basically saying when a caller of a modulescript leaves, the function breaks?
Does it not work anymore for anyone else?
(by the way, please use ``` for your code.)
yes it stops working, it can be called by anyone, but that thread that was called just stops.
So basically, whenever someone leaves, their function stops, but it can still be called after that (by a different person)?
it’s a module function that can be called by anyone, even at the same time. it just runs a function which ragdolls the person that they called for
the issue is that after the wait(), if the user leaves, then the script just stops working
it doesnt unragdoll them and execute like it should. it just stops
From my understanding of ModuleScripts, even though it is stored in ServerScriptService, the function itself is loaded onto the script inside of the player and is not loaded again after the player joins. Since this is happening, the function inside of the module script is more or less running in the script that calls the function. I feel like I made this a lot more confusing than it should’ve been, maybe someone else can take over for explaining
tl;dr since the function is in the script that’s calling the function, it would break upon a player leaving because the function itself is not on the server and still on a script on the player
That’s how functions work. If a player leaves, their functions stop. They are no more.
but isn’t it ran server side? shouldn’t it continue after the user leaves… that’s what’s confusing me
the function is on a module script and that function breaks if the caller, from another server script leaves, then it stops working- it breaks.
This is expected behaviour. Assuming you literally mean a player’s server script, the script is attached to their character and furthermore their Player object. If they leave, the script is destroyed.
Players who’ve left can’t interact with the server. In your case, after wait(n), your code assumes that the character is still in the server and attempts to perform actions on potentially nil characters. It’d be helpful to check your console, since it’s probably throwing an error.
This is an issue in your implementation and needs to be adjusted to accommodate player states. For me personally, I push this kind of code into the character altogether.
You’re making my brain hurt. It’s a serverscript, yes, but if a player leaves, the functions in it (i.e humanoid dies) does not fire, since the player leaves.
the script is in server script service
the player’s script is destroyed yes, but it already called the module’s function