CFrame expected, got nil error

So im making a enemy tool script for my game, and basically what the system is is that if the player takes long enough to collect a tool, the monster will collect the tool in the map

And im making a test by teleporting the player to the tool
And im making it so its more optimized by removing the spaces of the item names and using them to get the item on toollocations table

But theres an error saying CFrame expected, got nil

Can anyone help me with that?

The Script

local toollocations = {
    BraveHammer =,1,1)

for i,v in pairs(game.Workspace.ToolLocations) do
    local newv = string.gsub(v, " ", "")
    game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = newv

Right now you are trying to set the CFrame of the character to a string newv. You probably want to set character.CFrame = toollocations[newv] instead. You’ll also want to do v.Name in your gsub.

Ohh now it worked, thx!


It is worth noting that you don’t have to trim the spaces in order to get the item from your table if the item has spaces in the key as well. Additionally if these are tools they probably have a handle so you could just teleport players to the position of the handle (though you might need to check it exists first).

Oh yeah, i changecd that after i posted this post