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

A script meant to disable multiple scripts (100+) only changes a few?

Hello! I'm making an obby and I have a script which disables the script of every kill part if you have a certain gamepass, sort of like an easy mode. However, they only work on a few of them, and they're all parts I made first, before all the others. Additionally, I discovered that the scripts that do get disabled, are disabled for everyone in the server, which I don't want. An error pops up "Script is not a valid member of Part", I don't understand why this happens.

Easy Mode Script:

local id = #######

local killPartFolder = game.Workspace.killParts 

for i, part in pairs (killPartFolder:GetChildren()) do
    
end

game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
    if purchased and id == ido then
        for i, part in pairs (killPartFolder:GetChildren()) do
            part.Script.Disabled = true
        end
    end
end)

game.Players.PlayerAdded:Connect(function(plr)
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,id)then
        for i, part in pairs (killPartFolder:GetChildren()) do
            part.Script.Disabled = true
        end
    end
end)

I'll also add the script for the kill parts. It doesn't actually "kill" the player, it teleports them back to their last checkpoint.

Kill Script:

local debounce = false

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local tp = workspace.Stages[player.leaderstats.Stage.Value]
	local char = hit.Parent
    if debounce == false then
        if char:FindFirstChild("Humanoid") then
            char:moveTo(tp.Position + Vector3.new(0,10,0))
            wait(1)
        end
        debounce = false
    end
end)

3 answers

✓ Accepted answer

As for the error Script is not a valid member of Part make sure that all of the killbricks you have are actually killbricks. It's literally saying some of them have no script below them (which in term means they aren't killbricks).

Additionally it's far better to use some kind of BoolValue object stored in the player which contains true/false whether or not the user has the gamepass. Then let the killbricks determine if they should teleport the player back based on that BoolValue. Do not disable the script.

1 comment

0

Thank you! This works!

This is a very inefficient way of doing things, because client scripts cannot disable server scripts, and server scripts cannot destroy server scripts for only specific players. This whitelist should be built into the kill parts themselves, e.g.

function getplayer(instance)
    for _, v in pairs(Players:GetPlayers()) do
        if v.Character and (instance:IsDescendantOf(v.Character) or instance == v.Character) then
            return v
        end
    end
end

script.Parent.Touched:Connect(function(hit)
	local player = getplayer(hit)
	if player and player.Character.Humanoid and not game:GetService("MarketPlaceService"):UserOwnsGamePassAsync(player.UserId, gamepassId) then
		player.Character.Humanoid:TakeDamage(math.huge)
	end
end)

3 comments

0

UserOwnsGamePassAsync yields for each request, therefore making this solution even worse in terms of performance.

0

The ideal solution would be for him to implement a universal handler for this and pre-check gamepass requirements, but he's clearly not advanced enough to implement that since he's using probably free-model kill parts.

0

I don't use free model kill parts, nearly everything in my game I've made myself. How do you assume I use free models based off this post? Yes, I'm not advanced in lua, but I could probably figure out how to implement that.

Disabling scripts on its own is really bad practices. Disabling hundreds of them, that would be critical. I suggest using Bindable Events instead, it's way cleaner, although you're gonna need to edit those 100 scripts.

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