Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

"IF" statement not working properly?

Asked by
Paldi 109
6 years ago

Hello, im making a touch event where when a player touch the part, it looks in the player's gui to see if a certain value is named the same as the one in the part and if it isn't then it adds a new button but now it adds a new button even if there is the same value

db= false 

function handleTouch(otherPart)
    local character = otherPart.Parent
    local humanoid = character:FindFirstChild('Humanoid')
    local player = game.Players:FindFirstChild(character.Name)
    local gun = script.Parent.Parent.WepName --this is the first value
    if humanoid and db == false then
        db = true
        local buttons = player.PlayerGui.Weapons.Frame:GetChildren()
        for i = 1,#buttons do
            if buttons[i].ClassName == "ImageLabel" then
                if buttons[i].WepName.Value ~= gun.Value then --here is the part where it looks if it has the same value or not but even when its the same it will clone the button when it should only clone it if it isnt (~=)
                    local newbutton = player.PlayerGui.Weapons.Frame:FindFirstChild("Button 1"):Clone()
                    local num = tostring(i)
                    newbutton.Name = "Button "..num
                    newbutton.Parent = player.PlayerGui.Weapons.Frame
                    newbutton.ButtonNumber.Value = num
                    newbutton.Ammo.Value = 50
                    newbutton.WepName.Value = gun.Value
                    newbutton.Number.Text = num
                else
                    buttons[i].Ammo.Value = buttons[i].Ammo.Value + 50
                end
                script.Parent.Parent.PrimaryPart.Transparency = 0.6
            end
        end
        wait(5)
        script.Parent.Parent.PrimaryPart.Transparency = 0
        db = false
    end
end

script.Parent.Touched:connect(handleTouch)
0
I'm pretty sure it's "=~" not "~=", but I don't really know if that matters. 0HappyManDudeguy0 15 — 6y
0
nah its "~=" else it gives an error :P Paldi 109 — 6y

Answer this question