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

"attempt to concatenate Instance with string" error, how can i fix this?

Asked by 3 years ago
Edited 3 years ago

I have a spawn plot system that makes a new plot (for a 3d main menu thing) whenever a new player joins, but it doesn't delete the model once the player leaves the main menu and enters the actual game (and i don't think it does when the player leaves either), so it just makes unnecessary lag in bigger servers, so i wanted to fix that.

I used a script (local) in the play button that fires a remote event with one reference, the username of the player who pressed it, the remote event is listened by a script inside the spawn plot itself that checks if the owner of the plot (the name that was sent through the button) is the same as the name of the user plus the word "plot" (which is the name of the plot, for every player)

However, when it's time to get rid of the model, it doesn't and throws out this error message

"Workspace.SpawnModels.ArisNetaplot.Script:6: attempt to concatenate Instance with string"

Does anyone here know how to deal with this? it'd be really great if i could get this sorted soon, since it's something i've been meaning to fix for a long while but never was able to get around to it, many thanks!

(code samples below)

script sample of the script that fires the event

local plr = game.Players.LocalPlayer.Name

function OnClicked() 
    script.Parent.Visible = false
    wait(5)
    workspace.PlayerSpawnedEvent:FireServer(function(plr)
    end)

script sample of the listener

workspace.PlayerSpawnedEvent.OnServerEvent:Connect(function(plr)
    --wait(5)
    local plot = script.Parent
    print(plot.Name)
    print(plr)
    if plot.Name == plr.."plot" then
        script.Parent:Destroy()
    end
end)

Also, just a little side note, the prints are exactly the same in the output (just that one has "plot" after it, but that's meant to happen), if that's useful.

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

You need to do plr.Name, if you don't do this then the game will interpret it as the literal player object, instead of the name of the player. Adding two (or more) strings together requires that both inputs are strings.

0
thank you so much! at first i didn't know where to put plr.Name but i got it to work and i'm super thankful! ArisNeta 48 — 3y
Ad

Answer this question