Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I reference the model I created without renaming it?

I'm designing my player data saves and the data is named the players Id. That works for the first half of my code, but when I try to reference it in the addRequiredParts() function my output reads the error "UserId is not a valid member of RBXScriptSignal" I'm probably just being dumb but I can't find the error

local function addRequiredParts(player)
	local playerID = player.UserId
	local Location = game.ReplicatedStorage.playerData.playerID.givenValues
	local tempVar = Instance.new("BoolValue")
	tempVar.Name = "newPlyr"
	tempVar.value = false
	tempVar.Parent = Location
	tempVar = nil
	local tempvar = Instance.new("NumberValue")
	tempvar.Name = "forceMastery"
	tempvar.value = nil
	tempvar.Parent = Location
	tempvar = nil
	local tempvar = Instance.new("NumberValue")
	tempvar.Name = "forceEndurance"
	tempvar.value = 100
	tempvar.Parent = Location
	tempvar = nil
	local tempvar = Instance.new("BoolValue")
	tempvar.Name = "usingForce"
	tempvar.value = false
	tempvar.Parent = Location
	tempvar = nil
	local tempvar = Instance.new("NumberValue")
	tempvar.Name = "forceSrength"
	tempvar.Value = nil
	tempvar.Parent = Location
	tempvar = nil
end



game.Players.PlayerAdded:Connect(function(player)
	local newData = Instance.new("Model") 
	local playerID = player.UserId
	newData.Name = (playerID)
	newData.Parent = game.ReplicatedStorage.playerData
	local playerValues = Instance.new("Model")
	playerValues.Name = "givenValues"
	playerValues.Parent = newData
	addRequiredParts(player)
end)

1 answer

✓ Accepted answer

Your error was here:

local player = game.Players.PlayerAdded

The PlayerAdded event fires when a player enters the game, you cannot reference like a value. I will return a modified version of your script and you tell me if it works please.

local function addRequiredParts(player)
    local playerID = player.UserId
    local Location = game.ReplicatedStorage.playerData.playerID.givenValues
    local tempVar = Instance.new("BoolValue")
    tempVar.Name = "newPlyr"
    tempVar.value = false
    tempVar.Parent = Location
    tempVar = nil
    local tempvar = Instance.new("NumberValue")
    tempvar.Name = "forceMastery"
    tempvar.value = nil
    tempvar.Parent = Location
    tempvar = nil
    local tempvar = Instance.new("NumberValue")
    tempvar.Name = "forceEndurance"
    tempvar.value = 100
    tempvar.Parent = Location
    tempvar = nil
    local tempvar = Instance.new("BoolValue")
    tempvar.Name = "usingForce"
    tempvar.value = false
    tempvar.Parent = Location
    tempvar = nil
    local tempvar = Instance.new("NumberValue")
    tempvar.Name = "forceSrength"
    tempvar.Value = nil
    tempvar.Parent = Location
    tempvar = nil
end



game.Players.PlayerAdded:Connect(function(player)
    local newData = Instance.new("Model") 
    local playerID = player.UserId
    newData.Name = (playerID)
    newData.Parent = game.ReplicatedStorage.playerData
    local playerValues = Instance.new("Model")
    playerValues.Name = "givenValues"
    playerValues.Parent = newData
    addRequiredParts(player)
end)

Again, if this does work, please consider making this an accepted answer.

3 comments

0

It still fails to refrence the model saying "not a valid member of model"

0

However I am glad you caught that

0

Can you tell me which line this errors at?

This discussion is preserved as it was. New answers, comments, and votes are closed.