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

How to convert a string value into an object name?

Asked by
Galicate 106
6 years ago
Edited 6 years ago

I have a script that brings an error that says Unable to cast value to object...Someone help???

local Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
local equipped = false
local primary = Player.PlayerData.Inventory.PrimaryTool.Value
local secondary = Player.PlayerData.Inventory.SecondaryTool.Value
print(primary.." "..secondary)

Mouse.KeyDown:connect(function(Key)
    if(Key:lower() == "1") then
        if equipped == false then
        Player.Character.Humanoid:EquipTool(primary)
        equipped = true
        print("equipped primary")
        elseif equipped == true then
        Player.Character.Humanoid:UnequipTools()
        equipped = false
        print("unequipped primary")
        end
        end
    if(Key:lower() == "2") then
        if equipped == false then
        Player.Character.Humanoid:EquipTool(secondary)
        equipped = true
        print("equipped secondary")
        elseif equipped == true then
        Player.Character.Humanoid:UnequipTools()
        equipped = false
        print("unequipped secondary")
        end
        end
end)
0
Don't think it's possible to convert a string to an 'object name' type since an object name isn't a type. Need more specific information to help your problem. PreciseLogic 271 — 6y
0
Is the `PrimaryTool` an `ObjectValue`? TheeDeathCaster 2368 — 6y
0
No the primary tool is a string value Galicate 106 — 6y
0
let me update this with more of my script Galicate 106 — 6y
0
Have you tried `Player.PlaayerData.Inventory[PrimaryTool.Value]`? TheeDeathCaster 2368 — 6y

1 answer

Log in to vote
-1
Answered by 6 years ago

Try to do PrimaryTool.Value:tostring()

0
nil value :P Galicate 106 — 6y
Ad

Answer this question