Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 3 years ago

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?

0
So, do you want to kill the script locally or in server? BestCreativeBoy 1395 — 3y
0
Locally DelvverPrevver 5 — 3y
0
If you kill a script locally, it will reset on respawn. So, you have to keep destroying it in a loop on respawn BestCreativeBoy 1395 — 3y
0
I tried using a while wait() loop and it didnt seem to work. Is there any way of looping that you reccomend? DelvverPrevver 5 — 3y
View all comments (7 more)
0
Here's the new script after i added a loop DelvverPrevver 5 — 3y
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 DelvverPrevver 5 — 3y
0
I added an answer try checking that out BestCreativeBoy 1395 — 3y
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. JesseSong 3916 — 3y
0
Try using a loop to stimulate that. JesseSong 3916 — 3y
0
Tried using what you said and it still kicked when I reset. DelvverPrevver 5 — 3y
0
If you are using a loop you could simply use break. If not :Destroy() is the only option. WideSteal321 773 — 3y

3 answers

Log in to vote
1
Answered by 3 years ago

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)

Ad
Log in to vote
0
Answered by 3 years ago

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

0
I have already tried that, but it still runs when I reset. DelvverPrevver 5 — 3y
Log in to vote
0
Answered by
zane21225 243 Moderation Voter
3 years ago

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)
1
Thank you so much, this works perfectly! I'd upvote you but I dont have enough rep :(. Thanks so much again! DeIvverPrevver 1 — 3y
0
I was looking through my old posts and glad I could help :D zane21225 243 — 2y

Answer this question