game.GetWorld() not working

Im makeing something so if someone welds or puts a slider on a ragdoll to the world it deletes the constraint but for some reason game.GetWorld() is not working.

function RagdollFix()	local entnum = ents.GetAll()
	local players = player.GetAll()
	for _, ent in pairs(entnum) do
		if ent:GetClass() == "prop_ragdoll" then
			if constraint.FindConstraint( ent , "Weld" ) or constraint.FindConstraint( ent , "Slider" ) then
				for ali, All in pairs( constraint.GetAllConstrainedEntities( ent ) ) do
					if All == game.GetWorld() then
						for pl, ply in pairs(players) do
							local spawn = ply:Nick()
							local id = tostring(ply:SteamID())
							local color = ply:Team()
							umsg.Start( "player_ragchat")
					constraint.RemoveConstraints( ent , "Weld" )
					constraint.RemoveConstraints( ent , "Slider" )
hook.Add( "Think", "RagdollFix", RagdollFix)

If you would’ve printed the variable All, you’d have known that it is never equals to world. game.GetWorld() works perfectly.

Then how would i make this work.

Edit the tool on your server?

Actually it doesn’t work clientside.

What do you mean edit the slider and weld tool because this is a script?

Yes. They are located in gamemodes/sandbox/weapons/gmod_tool/stools/

Or you could try using CanTool hook, but it would be tricky.

[editline]12th May 2014[/editline]

I beg to differ.

And besides, this is a serverside script.

Is there a way to do this with out editing the tools and fix the script

function RagdollFix( ply, tr, tool )
	if ( (tool != "weld" && tool != "slider") || !ply.GetWeapon || !IsValid( ply:GetWeapon( "gmod_tool" ) ) ) then return end

	local e1 = ply:GetWeapon( "gmod_tool" ):GetToolObject():GetEnt( 1 )
	local e2 = tr.Entity

	if ( IsValid( e1 ) && e1:GetClass() == "prop_ragdoll" && e2 == game.GetWorld() ) then
		if ( SERVER ) then ply:ChatPrint( "No crashing, kthx" ) end // Give him a warning
		return false // Prevent the user from firing toolgun
	if ( IsValid( e2 ) && e2:GetClass() == "prop_ragdoll" && e1 == game.GetWorld() ) then
		if ( SERVER ) then ply:ChatPrint( "No crashing, kthx" ) end
		return false
hook.Add( "CanTool", "RagdollFix", RagdollFix)

I didn’t feel like lazy, so here you go.

Thanks a lot :slight_smile:


The right click function on the slider still works

[editline]12th May 2014[/editline]

This there any way to make it so you can’t right click aswell