Hello, this is my first time posting on the developer forum, so apologies if I get anything wrong.
What am I trying to achieve?
So, I am making a game with my friend where we host competitions for specific prizes in; and so I would like to be able to disable options using a script.
So for example, I would like to disable spectating during hide and seek competitions so contestants cannot see where other contestants are.
What have I tried?
I tried using BoolValues in a folder but I have still been coming across the same error, and I havenât found any solutions for this problem on the developer forum.
What is the code relating to this issue?
There is a custom commands script in the game for setting âonâ and âoffâ values for the attributes of the Configuration object, it does change the values to either âtrueâ or âfalseâ (I found out because I printed the attribute)
Note: All the attributes in the Configuration object are set to the boolean value.
Firstly, here is the script for the custom commands: (Edited to only relate to the specific issues)
local admins = {"BertNB", "baconboifanlol", "mepoorso", "Bapak_adelio", "ViMau007"}
eventSettings = game.ReplicatedStorage:WaitForChild("EventSettings")
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(c)
if table.find(admins, plr.Name) ~= nil then
local split = string.split(c, " ")
if split[1] == "!nukes" then
if split[2] == "on" then
eventSettings:SetAttribute("Nukes_Enabled", true)
end
if split[2] == "off" then
eventSettings:SetAttribute("Nukes_Enabled", false)
end
end
if split[1] == "!spectate" then
if split[2] == "on" then
eventSettings:SetAttribute("Spectating_Enabled", true)
end
if split[2] == "off" then
eventSettings:SetAttribute("Spectating_Enabled", false)
end
end
if split[1] == "!ghost" then
if split[2] == "on" then
eventSettings:SetAttribute("Ghost_Mode_Enabled", true)
end
if split[2] == "off" then
eventSettings:SetAttribute("Ghost_Mode_Enabled", false)
end
end
end
end)
end)
Now for the scripts that are ignoring the :GetAttribute() values from the Configuration object and going straight to executing:
This script is a âLocalScriptâ in a spectating GUI for detecting if the Spectating_Enabled attribute is true.
cam = game.Workspace.CurrentCamera
local bar = script.Parent.Bar
local title = bar.Title
local prev = bar.Previous
local nex = bar.Next
local button = script.Parent.Button
local spectateEnabled = game.ReplicatedStorage:WaitForChild("EventSettings"):GetAttribute("Spectating_Enabled")
function get()
for _,v in pairs(game.Players:GetPlayers())do
if v.Name == title.Text then
return(_)
end
end
end
local debounce = false
button.MouseButton1Click:connect(function()
if spectateEnabled == true then
if debounce == false then debounce = true
bar:TweenPosition(UDim2.new(.5,-100,0.88,-50),"In","Linear",1,true)
pcall(function()
title.Text = game.Players:GetPlayerFromCharacter(cam.CameraSubject.Parent).Name
end)
elseif debounce == true then debounce = false
pcall(function() cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid end)
bar:TweenPosition(UDim2.new(-1,-100,0.88,-50),"In","Linear",1,true)
end
end
end)
prev.MouseButton1Click:connect(function()
if spectateEnabled == true then
wait(.1)
local players = game.Players:GetPlayers()
local num = get()
if not pcall(function()
cam.CameraSubject = players[num-1].Character.Humanoid
end) then
cam.CameraSubject = players[#players].Character.Humanoid
end
pcall(function()
title.Text = game.Players:GetPlayerFromCharacter(cam.CameraSubject.Parent).Name
end)
end
end)
nex.MouseButton1Click:connect(function()
if spectateEnabled == true then
wait(.1)
local players = game.Players:GetPlayers()
local num = get()
if not pcall(function()
cam.CameraSubject = players[num+1].Character.Humanoid
end) then
cam.CameraSubject = players[1].Character.Humanoid
end
pcall(function()
title.Text = game.Players:GetPlayerFromCharacter(cam.CameraSubject.Parent).Name
end)
end
end)
Here is a âLocalScriptâ in a GUI for exploding everyone in the server. (nuking)
----- Variables -----
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local nukesOn = ReplicatedStorage:WaitForChild("EventSettings"):GetAttribute("Nukes_Enabled")
local player = Players.LocalPlayer
local nukeButton = script.Parent
local oldText = nukeButton.Text
local nukeProductId = ReplicatedStorage:WaitForChild("NukeServer"):GetAttribute("ProductID")
----- Events -----
nukeButton.Activated:Connect(function()
if nukesOn == true then
MarketplaceService:PromptProductPurchase(player, nukeProductId)
else
script.Parent.Text = "sorry bud.. nukes are disabled!"
task.wait(1)
script.Parent.Text = oldText
end
end)
Now finally, here is a server-sided script for making spectators ghosts (basically them being able to pretend like theyâre alive to not bore them while they are waiting to be in a competition to be brought back)
script.Parent.ClickDetector.MouseClick:Connect(function(p)
if game.ReplicatedStorage.EventSettings:GetAttribute("Nukes_Enabled") == true and p.Team == game.Teams.Spectators and not p.Backpack:FindFirstChild("Fly") or not p.Character:FindFirstChild("Fly") then
game.ServerStorage.Fly:Clone().Parent = p.Backpack
p.Character.Humanoid.MaxHealth = math.huge
p.Character.Humanoid.Health = math.huge
for i,v in p.Character:GetChildren() do
if v:IsA("Part") == true and v.Name ~= "HumanoidRootPart" then
v.Transparency = 0.6
end
if v:IsA("Accessory") == true then
v:FindFirstChild("Handle"):FindFirstChildOfClass("SpecialMesh").TextureId = ""
v:FindFirstChild("Handle").Transparency = 0.6
v:FindFirstChild("Handle").Color = p.Character.Head.Color
end
end
end
end)
Thank you for reading.