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

why does it not print out the boolean value?

Asked by 6 years ago
game.Players.PlayerAdded:connect(function(plr)  
    local shop = plr.PlayerGui:WaitForChild("SHOP")
    local DaggerB = shop.Frame.Weapons.Dagger
    local DaggerBtext = DaggerB:WaitForChild("Info").Text
    local DaggerOwned = DaggerB:WaitForChild("Owned")
    DaggerOwned.Value = DaggerDS:GetAsync(Id) or false
 print("Dagger Owned = "..DaggerOwned.Value)
end)

error Error attempt to concatenate field 'Value' (a boolean value) i need this for a data store.

--if you can be bothered to read it--
local DS = game:GetService("DataStoreService")
local DaggerDS = DS:GetDataStore("DaggerDS")

game.Players.PlayerAdded:connect(function(plr)  
    local shop = plr.PlayerGui:WaitForChild("SHOP")
    local DaggerB = shop.Frame.Weapons.Dagger
    local DaggerBtext = DaggerB:WaitForChild("Info").Text
    local DaggerOwned = DaggerB:WaitForChild("Owned")
    local Id = plr.UserId
    DaggerOwned.Value = DaggerDS:GetAsync(Id) or false
 print("Dagger Owned = "..DaggerOwned.Value)    

    if DaggerOwned.Value == false then
        DaggerBtext = "Price: 0"
    else
        DaggerBtext = "OWNED"
    end 

    DaggerOwned.Changed:Connect(function()
        DaggerDS:SetAsync(Id, DaggerOwned.Value)
         print(DaggerOwned.Value)
    end)
end)

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

An error should show you the line at which the error occurred. In your case it would be line 12 since this is the only place you use the concatenate operator.

print("Dagger Owned = "..DaggerOwned.Value) 

In Lua we cannot concatenate a string with a Boolean though I do not know why this is the case. It may be down to how a Boolean should be represented ie 0/1 or true/false.

The simplest way to resolve this is to just provide it as a second argument.

print("Dagger Owned = ", DaggerOwned.Value) 

But you can convert this boolean to a string representation using tostring

I hope this helps.

Ad

Answer this question