Attempt to index nil with 'Clone'

getting an error as stated above, "attempt to index nil with ‘Clone’

the thing i am trying to clone is a BoolValue inside of a folder in ReplicatedStorage:

image

script inside of server script service:

local e = game.ReplicatedStorage.Events.Setup.ColourSet
local storage = game.ReplicatedStorage.Colours

e.OnServerEvent:Connect(function(player)
	local colour = player.PlayerGui.Spinner.Background.Results.Text
	local item = storage:FindFirstChild(colour):Clone()
	item.Parent = player.Character
end)

Can you please show us the output?

it means it isn’t able to find colour inside the folder so just add this:

if storage:FindFirstChild(colour) then
local colour = player.PlayerGui.Spinner.Background.Results.Text
local item = storage:FindFirstChild(colour):Clone()
item.Parent = player.Character
end

Would you mind doing this:

print(storage:FindFirstChild(color))

And see what it says?

this would just skip over it if it couldnt find it though wouldnt it?

1 Like

getting nothing in output, but still the colour is not being added

Can you print colour and show/tell us what it says

It might be the text not changing, make sure to click outside the textbox before finding the color

nothing is printed in output if i try to print the colour

what do you mean by ‘click’ ? im doing this in a script

but you’re typing the color inside a text box aren’t you?

Try this:

local e = game.ReplicatedStorage.Events.Setup.ColourSet

e.OnServerEvent:Connect(function(player)
	local colour = player.PlayerGui.Spinner.Background.Results.Text
	local item = game.ReplicatedStorage.Colours:FindFirstChild(colour):Clone()
	item.Parent = player.Character
end)

no… the text is changed locally and it works fine, once it is changed i fire an event and pick it up on the server and then find the colour based on the text in the gui.

thats the problem, you change the text locally

1 Like

That’s the problem:

You have to change the text not locally or get the text locally. One way you can get the text locally is using a RemoteFuntion.
Example:

LocalScript in StarterPlayerScripts

local e = game.ReplicatedStorage.GetColor
local player = game.Players.LocalPlayer
e.OnClientInvoke = function()
    return player.PlayerGui.Spinner.Background.Results.Text
end

Then in your script:


local e = game.ReplicatedStorage.Events.Setup.ColourSet
local storage = game.ReplicatedStorage.Colours
local GetColor = game.ReplicatedStorage.GetColor

e.OnServerEvent:Connect(function(player)
	local colour = GetColor:InvokeClient()
	local item = storage:FindFirstChild(colour):Clone()
	item.Parent = player.Character
end)
1 Like

if i dont change the text locally then it will change for everyone

send the text to the server with the remote

i’m getting the same error again

how would i do this? sorry i dont understand this much