Hello, so I’m making a script right now to enable multiple scripts. Here’s what I have:
And what I’m trying to make is a script to enable both (if they are a certain rank) using the GetChildren() and :IsA() instance. But, it’s not working.
Here’s the script I currently have:
local plr = game.Players.LocalPlayer
local part = game.Workspace.Part
for i, child in ipairs(part:GetChildren()) do
if child:IsA("Script") then
if plr:IsInGroup(9099786) == false then
child.Disabled = true
elseif plr:GetRankInGroup(9099786) <= 5 then
child.Disabled = false
end
end
end
Does anyone know why it is not working and how to fix it?
What is “plr” ? The script you provided doesn’t define it anywhere.
Also, this script wouldn’t work anyway. You would have to enable them on the server since they’re server scripts which means it’ll be enabled for everyone even if they aren’t in the group
Since this is a local script (i’m assuming), this won’t work because the client can’t enable/disable server scripts. Changed made on the client won’t replicate to the server, so on the server, these scripts are still disabled.
Whatever the scripts do, you’d have to try to move them to work client-sided
Ok, so one of the scripts give a hat and another gives a shirt. How can I possibly move them to work client-sided? And yes, it is a local scripts inside StarterPlayerScripts.
If you’re familiar to remote events, you could try this:
-- local script
local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("RemoteEvent") -- this finds a remote in ReplicatedStorage with the given name
local player = game.Players.LocalPlayer
local groupId = 9099786
local debounce = false -- this is used for the Touched event
local function playerIsInGroup(id: number) : boolean
-- this function is used to find out if the player is in the group
return player:IsInGroup(id) -- this returns "true" or "false"
end
local function getPlayerRank(id: number) : number
-- this function returns the tank the player is, in the group
return player:GetRankInGroup(id) -- returns a number ranging 0 and 255
end
local function isLocalPlayer(object: BasePart) : boolean
-- this function checks if whatever touched the part was part of the player's character
return game.Players:GetPlayerFromCharacter(object) == player -- this also returns "true" or "false"
end
workspace.Part.Touched:Connect(function(hit)
if not debounce and playerIsInGroup(groupId) and getPlayerRank(groupId) > 5 and isLocalPlayer(hit.Parent) then
-- this checks if the debounce is enabled, and if the player's rank in the group is greater than 5
debounce = true
remote:FireServer({{"Shirt", 0000}, {"Hat", 0000}})
-- "0000" can be replaced with whatever you need to send, or you don't have to send a second argument at all
-- this sends an event for the server to pick up
wait(1)
debounce = false
-- this resets the debounce
end
end)
-- server script
local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("RemoteEvent")
remote.OnServerEvent:Connect(function(player, data)
-- roblox automatically passes the player who fired the event first
-- "data" is the name of the parameter of the arguments we sent from the local script
-- block exploiters (only the client checked for the player's requirements)
if player:GetRankInGroup(9099786) <= 5 then
player:Kick("Lol nice try")
end
local content = {
-- this table holds the name of the items and the functions to run with optional parameters
["Shirt"] = function(...)
-- code to give a shirt
end,
["Hat"] = function(...)
-- code to give a hat
end
}
for _, tbl in ipairs(data) do
-- this loops through the data we sent and checks everything
if content[tbl[1]] then
-- this checks the "content" table and tries to find it contains the index, and if it does, run the function that it's connected to
coroutine.wrap(content[tbl[1]])(tbl[2])
end
end
end)