Ok so I have some code for my game that requires a BoolValue to be ticked. When it is ticked, nothing prints even though the event was fired.
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local head = character:WaitForChild("Head")
local distanceMin
local distance
local closestPlayer
UserInputService.InputBegan:Connect(function (input, IsTyping)
if input.KeyCode == Enum.KeyCode.E and IsTyping == false then
distanceMin = math.huge
for _, player in pairs(Players:GetPlayers()) do
if player ~= LocalPlayer then
local iscrawling = player:WaitForChild("iscrawling")
if iscrawling.Value == true then
distance = player:DistanceFromCharacter(head.Position)
if distance < distanceMin then
distanceMin = distance
closestPlayer = player
print(closestPlayer.Name .. " is the closest player.")
end
end
end
end
if distanceMin < 10 then
print(closestPlayer.Name .. " is the closest player.")
end
end
end)
Try using a function when the BoolValue is true, use the BoolValue’s .Changed event and connect with the function
Sort of like this
iscrawling.Changed:Connect(function() -- here it is
distance = player:DistanceFromCharacter(head.Position)
if distance < distanceMin then
distanceMin = distance
closestPlayer = player
print(closestPlayer.Name .. " is the closest player.")
end
end)
Is the boolvalue directly parented to the player or in a folder?
Try putting a print over here:
local iscrawling = player:WaitForChild("iscrawling")
if iscrawling.Value == true then
-- here
distance = player:DistanceFromCharacter(head.Position)
if distance < distanceMin then
distanceMin = distance
closestPlayer = player
print(closestPlayer.Name .. " is the closest player.")
end
You don’t need to use :GetPropertyChangedSignal("Value") for ValueBase objects since they have a modified .Changed event that only fires when Value property changes.
How did you set the value? Did you set it in a script, local script, or manually? I had a problem where I set a value in a local script so it was registered as false by the server, which may or may not be the problem.
That’s probably the problem then. If you set it in a local script it won’t replicate to other clients or the server so you would need to use a server script to set the value (or send a remote to the server to set the value).