Lately I have been working a lot with LocalScripts, and in my script it basically relies on these BoolValues I have made. However, when I set the values to either true or false, they never actually set them to true or false. I was wondering, is there some sort of special method to setting BoolValues in LocalScripts? Am I doing something wrong? My code below is completely unfinished, as I need the BoolValues to work in order to move on. And any extra variables you see that aren't being used are there because they will be used in the future. In addition, in case you were wondering, I am getting no errors. Here it is:
Setting players values:
game.Players.PlayerAdded:connect(function(plr)
local character = plr.Character
if not character or character.Parent == nil then -- what for character
character = plr.CharacterAdded:wait()
end
local val = Instance.new("BoolValue",character) -- set all variables needed
val.Name = "player"
local val2 = Instance.new("BoolValue",character)
val2.Name = "combat"
local val3 = Instance.new("BoolValue",character)
val3.Name = "talking"
local val4 = Instance.new("BoolValue",character)
val4.Name = "reading"
end)
The main LocalScript:
local player = game.Players.LocalPlayer -- setting variables
local mouse = player:GetMouse()
if not character or character.Parent == nil then
character = player.CharacterAdded:wait()
end
local selection = Instance.new("SelectionBox", player.PlayerGui)
selection.Color = BrickColor.new("Medium stone grey")
local cmbselection = Instance.new("SelectionBox", player.PlayerGui)
cmbselection.Color = BrickColor.new("Bright red")
mouse.Move:connect(function()
mouse.Icon = "http://www.roblox.com/asset/?id=184642130"
local combat = character.combat.Value
local talking = character.talking.Value --set more variables
local reading = character.reading.Value
local target = mouse.Target
if target and target.Parent:IsA("Model") then
local hum = target.Parent:FindFirstChild("Humanoid")
local plr = target.Parent:FindFirstChild("player")
local enemy = target.Parent:FindFirstChild("enemy")
local friend = target.Parent:FindFirstChild("friend")
local book = target.Parent:FindFirstChild("book")
if hum and plr == nil and enemy and combat == false then
mouse.Icon = "http://www.roblox.com/asset/?id=165194824"
selection.Adornee = target.Parent
mouse.Button1Down:connect(function()
local targetpos = target.Parent.Torso.Position
local distance = player:DistanceFromCharacter(targetpos)
if distance < 40 and combat == false then
combat = true --not setting combat to true
selection.Adornee = nil
cmbselection.Adornee = target.Parent
end
end)
elseif hum == nil or target == nil or plr == nil and combat == true then
mouse.Icon = "http://www.roblox.com/asset/?id=184642130"
selection.Adornee = nil
mouse.Button1Down:connect(function()
cmbselection.Adornee = nil
end)
end
end
end)
I hope my code wasn't too sloppy, thanks for reading.
