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

Why are two identical strings being detected as different?

Asked by 3 years ago
Edited 3 years ago

This question has been solved by the original poster.

Let's image partTouching value is "Flashlight". Now look at line 15. The first variable of the list is also "Flashlight". So, when I'm comparing the two, for some reason, roblox decides that "Flaslight" and "Flashlight" are different things. Am I comparing the wrong thing? Help, please.

local detector = script.Parent
local itemList = require(game.ServerScriptService:WaitForChild("Modules").ShopItems)
local itemValue = script.Parent.Parent.Item
local debounce = false


detector.Touched:Connect(function(partTouching)
    if debounce == false then
        tostring(partTouching)
        local debounce = true
        for i = 1, #itemList do
            print(partTouching)
            print(itemList[i])
            --print("something is touching")
            if partTouching == itemList[i] then
                if itemValue.Value == "" then
                    itemValue.Value = partTouching
                end
            end
        end
        detector.TouchEnded:Wait()
        local debounce = false
        itemValue.Value = ""
    end
end)

1 answer

Log in to vote
0
Answered by 3 years ago

It's fixed. When getting the part that hits the other part, make sure to compare using part.Name. In this case, I fixed it by writing:

if itemList[i] == partTouching.Name then

Instead of

if itemList[i] == partTouching then

Hope this helps to anyone.

Ad

Answer this question