Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I simply kill a script without using :Destroy()?

Hi. I've created a very simple script, where if you touch the parent, it kicks your client:

script.Parent.Touched:Connect(function(hit)
 local player = game.Players:GetPlayerFromCharacter(hit.Parent)
 player:Kick("You have been kicked.") 
end)

Now, with another script, I destroy the script with a LocalScript (StarterPlayer>StarterPlayerScripts):

local whitelist = {"namehere"}

local plr = game:GetService("Players").LocalPlayer
if table.find(whitelist, plr.Name) then
	game.Workspace.Brick:Destroy()
	return;
end

This deletes it on the client, but if I die or reset my character while standing where the brick would be, it kicks me as if it was still there.

How do I kill the script?

11 comments

0

So, do you want to kill the script locally or in server?

0

Locally

0

If you kill a script locally, it will reset on respawn. So, you have to keep destroying it in a loop on respawn

0

I tried using a while wait() loop and it didnt seem to work. Is there any way of looping that you reccomend?

0

Here's the new script after i added a loop

0

local whitelist = {"namehere"} local plr = game:GetService("Players").LocalPlayer if table.find(whitelist, plr.Name) then while wait() do game.Workspace.anti:Destroy() end return; end

0

I added an answer try checking that out

0

When a character dies, the old character model gets swapped with a new one, and the script will still be there! Try checking whether the part is not equal to nil if it is then destroy it.

0

Try using a loop to stimulate that.

0

Tried using what you said and it still kicked when I reset.

0

If you are using a loop you could simply use break. If not :Destroy() is the only option.

3 answers

Client changes do not replicate to the server, the client cant even see scripts, so you need to destroy the script on the server, but destroying/cloning/disabling/enabling scripts is a bad practice. If you want that the script doesnt kill you but others do then make the touched filter you out and kill the others if you just want to it stop killing at certain conditions then apply those conditions, but if you really want the client to turn on/off the killing mechanism then you can use a remote event to disconnect or connect the touched event

(script = server, localscript = client)

Destroy the script inside the brick instead of just the brick, then try to destroy the brick?

1 comment

0

I have already tried that, but it still runs when I reset.

A better way to do this is to put it all into a single script. Also, it's better if you whitelist by a player's UserId ineatd of their username.

-- Variables:
local whitelistID = {000101}
local kickReason = 'You have been kicked from this session'

script.Parent.Touched:Connect(function(touched)
	local plr = game.Players:GetPlayerFromCharacter(touched.Parent)
	if table.find(whitelistID, plr.UserId) then
		return
	else
		plr:Kick(kickReason)
	end
end)

2 comments

1

Thank you so much, this works perfectly! I'd upvote you but I dont have enough rep :(. Thanks so much again!

0

I was looking through my old posts and glad I could help :D

This discussion is preserved as it was. New answers, comments, and votes are closed.