Please note that the DevForum is not a resource to spoonfeed you code. It should be used to tackle concrete issues. With no background on how this code is run, it may be quite difficult to just “fix” the problem. Can you provide other information that may help us find a solution together?
This won’t work. It’s saying “if IntroTag is not true and AFK is true”, which is not what you want. You want:
if (not player.IntroTag.Value) and (not player.AFK.Value) then
table.insert(plrs,player) --add each players into plrs table
print(player)
colbert2677’s article on XY Problems is super useful for this kind of thing.
cc: @iSkepticalBoi
Yes So. Intro Default Value is true
and default value for AFK is False
(obviously). A Intro Starts When a player joins. When they click play the IntroTag is set to False. When they click AFK it makes AFK = True
Im using this for a round based game.
It was only meant to solve his conditional checks, not expected to work as is, obviously.
& @OP As EmilyBendsSpace pointed out, there were some logical fallacies in my snippet, I edited my original post to amend 'em;
This is a Issue Because the Game Dosent Work Properly and this is helping im not just Asking for the code.
Have you tried this solution yet?
Yes ive tried it. works for the first time when IntroTag
is True and When Both are False But When introTag
is False
and AFK = True
it inserts the player.
@Deferend @ImageLabel @AbiZinho @REALTimothy0812 @EmilyBendsSpace @Fm_Trick Would it be helpful for me to Show the Gui Intro Code that makes the Tag False
and the AFK that makes the Tag True
and False
?
You’ve got a problem unrelated to the logic of OR if Deferend’s code is inserting the player when one is true and you’ve doubled checked that you’ve got all the parentheses in the right places. His logic is correct and equivalent to my suggestion. If you’re leaving out parens, such that the order of operations of not and or operators is wrong, all bets are off. You can’t be casual with parentheses here.
You should print out the values of your value objects when you insert and remove. And make sure you’re actually using BoolValues and not assigning “true” and “false” to StringValue objects or something else weird. The word “false” is true in Lua.
Yes. Im Using the Parentheses right, i know what values can be used. (Im Using BoolValues or it would Error)
In Lua, if a value is not false or
nil
, it’s considered “true” when used in a conditional statement
Booleans
Can you show more code? Clearly there’s an issue with this, and I checked my code. Maybe it’s how you’re implementing it?
Ok Heres all the code that relevant.
Code for gui:
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Event = ReplicatedStorage:WaitForChild('LoadCharacter')
local EnableEvent = ReplicatedStorage:WaitForChild('EnableGui')
local target = workspace.Intro -- The object to rotate around
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.Focus = target.CFrame
local rotationAngle = Instance.new("NumberValue")
local tweenComplete = false
local player = game.Players.LocalPlayer
local cameraOffset = Vector3.new(50, 80, -50)
local rotationTime = 20 -- Time in seconds
local rotationDegrees = 360
local rotationRepeatCount = -1 -- Use -1 for infinite repeats
local lookAtTarget = true -- Whether the camera tilts to point directly at the target
local Play = script.Parent.Play
local Song = script.Parent.Nice
Play.MouseButton1Click:Connect(function()
Play:TweenPosition(UDim2.new(1.2,0,0.931,0), "Out", "Bounce", 1, false)
wait(1)
player.IntroTag.Value = false
Play:Destroy()
--EnableEvent:FireServer()
Event:FireServer()
wait(0.1)
target:Destroy()
camera:Destroy()
script.Parent:Destroy()
end)
Song:Play()
local function updateCamera()
local rotatedCFrame = CFrame.Angles(0, math.rad(rotationAngle.Value), 0)
camera.CFrame = rotatedCFrame:ToWorldSpace(CFrame.new(cameraOffset))
if lookAtTarget == true then
camera.CFrame = CFrame.new(camera.CFrame.Position, target.Position)
end
end
-- Set up and start rotation tween
local tweenInfo = TweenInfo.new(rotationTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, rotationRepeatCount)
local tween = TweenService:Create(rotationAngle, tweenInfo, {Value=rotationDegrees})
tween.Completed:Connect(function()
tweenComplete = true
end)
tween:Play()
-- Update camera position while tween runs
RunService.RenderStepped:Connect(function()
if tweenComplete == false then
updateCamera()
end
end)
This is Alot of Code.
AFK GUI Button
-- GetService and Other--
local UIS = game:GetService('UserInputService')
local epicblur = game.Lighting.Blur
local player = game.Players.LocalPlayer
-- Key Binds --
local AFKB = script.Parent.TextButton
local hotkeyController = Enum.KeyCode.ButtonR1
-- Text & Miscellaneous--
local Notice = script.Parent.AFK
AFKB.MouseButton1Click:Connect(function()
if AFKB.Text == 'AFK:OFF' then
player.AFK.Value = true
Notice.Visible = true
AFKB.Text = 'AFK:ON'
Notice:TweenPosition(UDim2.new(0.5,0,0.505,0), "Out", "Linear", 1)
print(player.Name..' AFK was Turned On.')
wait(0.5)
epicblur.Enabled = true
Notice.Text = 'AFK IN: 1'
wait(1)
Notice.Text = 'AFK IN: 2'
wait(1)
Notice.Text = 'AFK IN: 3'
wait(1)
Notice:TweenPosition(UDim2.new(1.5,0,0.505,0), "In", "Linear", 1)
epicblur.Enabled = false
Notice.Visible = not Notice.Visible
elseif AFKB.Text == 'AFK:ON' then
player.AFK.Value = false
Notice.Visible = true
AFKB.Text = 'AFK:OFF'
Notice:TweenPosition(UDim2.new(0.5,0,0.505,0), "In", "Linear", 1)
print(player.Name..' Is Now Back InGame.')
wait(0.5)
epicblur.Enabled = true
Notice.Text = 'AFK OFF: 3'
wait(1)
Notice.Text = 'AFK OFF: 2'
wait(1)
Notice.Text = 'AFK IN: 1'
wait(1)
Notice:TweenPosition(UDim2.new(1.5,0,0.505,0), "In", "Linear", 1)
epicblur.Enabled = false
Notice.Visible = not Notice.Visible
end
end)
--[[UIS.ImputBegan:Connect(function(key, gp)
if key.KeyCode == hotkeyController or key.KeyCode == bruh then
end
end)
--]]
Main Script
local plrs = {}
for i, player in pairs (game.Players:GetPlayers()) do
if (player.IntroTag.Value) or (player.AFK.Value) then
table.insert(plrs,player)--Add each players into plrs table
print(player)
--else
--warn(player, 'has Been Removed From Table - Intro Or AFK.')
--for i = 1, #plrs do
--if plrs[1] == Player then
--table.remove(plrs,i) --Remove Player from table if they are in the intro or AFK.
--[[ player.IntroTag.Changed:Connect(function(new_value)
if new_value == false then
print(player.Name.." 's New IntroTag Value:"..tostring(player.IntroTag.Value))
table.insert(plrs,player)
else
warn(player, 'has Been Removed From Table - Intro.')
table.remove(plrs,i)
end
end)
player.AFK.Changed:Connect(function(new_value)
if new_value == false then
print(player.Name.." 's New AFK Value:"..tostring(player.AFK.Value))
table.insert(plrs,player)
else
warn(player, 'has Been Removed From Table - AFK.')
table.remove(plrs,i)
end
end) --]]
end
end
Stats
game.Players.PlayerAdded:Connect(function(player)
playersLeft = playersLeft + 1
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Value = 0
wins.Parent = leaderstats
local buxs = Instance.new("IntValue")
buxs.Name = "Buxs"
buxs.Value = 0
buxs.Parent = leaderstats
local kills = Instance.new("IntValue")
kills.Name = "Kills"
kills.Value = 0
kills.Parent = leaderstats
local xp = Instance.new("IntValue")
xp.Name = "XP"
xp.Value = 0
xp.Parent = leaderstats
--local lvl = Instance.new("IntValue")
--lvl.Name = "Level"
--lvl.Value = 0
--xp.Parent = player
--lvl.Parent = player
local IntroTag = Instance.new('BoolValue')
IntroTag.Name = 'IntroTag'
IntroTag.Value = true
IntroTag.Parent = player
local AFK = Instance.new('BoolValue')
AFK.Name = 'AFK'
AFK.Value = false
AFK.Parent = player
Hope this Helps…
For the record, I wish that this was possible:
local value = 1
If value == 1 or 0 then
-- Code
end
It would automatically compare the value after the “or” keyword. This would save so much headache but, sadly, lua doesn’t work like this. Fun to think about.
Edit: Poorly worded. This is possible but not the way I wish it was intended.
Second Edit: Not sure why this was flagged…?
So i could do this to prevent the long coding?
So to clarify, you’ve tried my method without modifying the table in any other way? Because that code should look like:
local plrs = {}
for i, player in pairs(game.Players:GetPlayers()) do
if (not player.IntroTag.Value) and (not player.AFK.Value) then
table.insert(plrs,player) --add each players into plrs table
print(player.Name)
end
end
Note: it used to be print(player)
, but you cannot print a player object, to my knowledge.
Yes ive tried but it dosent work.
I’ve found your problem. It has NOTHING to do with the logic, just not accommodating for a FE environment;
Let me explain: If the client makes any changes (local script) to values, only the CLIENT will see these changes and not the SERVER. The code that checks these values on the server is not faulty, but the code that sets them is.
The bit that sets AFK to be true never replicates, so the server still reads it as false. This is why my code “Does not work”.
This code will help you debug the problem further. My bet is that when the code runs, the server thinks the values have not changed.
local Player = game.Players.LocalPlayer
local plrs = {}
for i, player in pairs (game.Players:GetPlayers()) do
print("Player "..player.." AFK value: "..player.AFK.Value)
print("Player "..player.." IntroTag value: "..player.IntoTag.Value)
if not player.IntroTag.Value and not player.AFK.Value then
table.insert(plrs,player)--Add each players into plrs table
print(player)
end
end
In summary, you can’t just set values from the client. More Info on how to understand this: Client-Server Runtime | Documentation - Roblox Creator Hub
The best way you can fix this problem is by using remote events and functions, which allow you to send data across the replication barrier.
At this point, your topic has been solved. The #development-support:scripting-support category is not a place to get spoon-fed scripts for free. We will not make a game for you. We can only help you in that journey. With that said, please refer to one of the 37 options above and mark the one that suit you best as the solution.
Thank you for letting me know. Im Surprized at myself that i overlooked that i wasnt using a RemoteEvent for the AFK. Thank you, @REALTimothy0812 @Deferend @ImageLabel @AbiZinho @sanjay2003 @EmilyBendsSpace @Fm_Trick . Im Going With @Deferend Method.