I’m having an issue with bool values. I’m making a trail giver that detects if the player has a trail unlocked, and if the trail is equipped. However, when I test it, it shows that the value is false when it is actually true.
Code:
local giveTrail = require(game.ReplicatedStorage.giveTrail)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
print("character found")
for i, button in pairs(player.Trails:GetChildren()) do
print("found")
if button.Value == true then
print("true")
if button.Equipped.Value == true then
print("true2")
giveTrail.giveTrail(button.Name, player)
end
elseif button.Value == false then
print("not true?!??!")
print(button.Value)
end
end
end)
end)
The owned and equipped values get changed through a local script in StarterGui.
Well the first thing I can see that’s probably causing it is t hat you’re changing them from a local script, is this a server script? If it is, then that’s why, you need to make a remoteevent to change them to the desired value so the server can detect the change
Right so, firstly, the values are in the player themselves if I’m guessing correctly? And may I see the code you have so far to change the values from the localscript
local gui = script.Parent
local trailFolder = gui.Trails
local player = game.Players.LocalPlayer
local giveTrail = require(game.ReplicatedStorage.giveTrail)
for i, button in pairs(trailFolder:GetChildren()) do
button.MouseButton1Click:Connect(function()
if player.Trails[button.Name] then
if player.Trails[button.Name].Value == true then
if player.Trails[button.Name].Equipped.Value == false then
player.Trails[button.Name].Equipped.Value = true
giveTrail.giveTrail(button.Name, player)
player.CharacterAdded:Connect(function()
giveTrail.giveTrail(button.Name, player)
end)
elseif player.Trails[button.Name].Equipped.Value == true then
player.Trails[button.Name].Equipped.Value = false
end
end
end
if player.Trails[button.Name] then
if player.Trails[button.Name].Value == false then
player.Trails[button.Name].Value = true
end
end
end)
end
Terribly sorry for the late response, I was asleep.
Basically, just put a RemoteEvent In replicatedStorage and put a script in ServerScriptService with this code
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, buttonName, value, setValue)
if setValue then
player.Trails[buttonName][setValue].Value = value
else
player.Trails[buttonName].Value = value
end
end)
And anytime you want to change a value, fire this event and give it the name of the button, the new value you want, and the thing in there you want to change (or jutst leave it blank if you want to do something like player.Trails[button.Name].Value. Example, to change what I just mentioned to true, you’d just do
game.ReplicatedStorage.RemoteEvent:FireServer(button.Name, true)
And for changing the equipped value, just do game.ReplicatedStorage.RemoteEvent:FireServer(button.Name, true, "Equipped")
You will need to make a variable to reduce the amount of repetition to get the RemoteEvent if you’ll be using it a lot