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

ServerScriptService.EquippedTextChange:8: attempt to index nil with 'Equiped' error?

HELLO! This is my 3rd time posting here and this is the error. here is the script script where the error is

local equippedgui = game.StarterGui.Inventory.Pets.ScrollingFrame

game.ReplicatedStorage["buncha remote events for no reason"].r2.OnServerEvent:Connect(function(hello)
	print("1 worked")
	if hello then
		print("2 worked")
		game.ReplicatedStorage["buncha remote events for no reason"].r3.OnServerEvent:Connect(function(player,newTemplate)
			if newTemplate.Equiped.Text == "Equipped" then
				newTemplate.Equiped.Text = "Unequipped"
				newTemplate.Equiped.TextColor3 = Color3.fromRGB(255,0,0)
			else
				newTemplate.Equiped.Text = "Equipped"
				newTemplate.Equiped.TextColor3 = Color3.fromRGB(0,255,0)
			end
		end)
	end
end)

Fireserver code

local camera = workspace.Camera
local studio = workspace.Studio
local template = script.Parent.Pets.ScrollingFrame.Template
local scrollingFrame = script.Parent.Pets.ScrollingFrame
local buttonConnection = {}
local sparkles = studio["Egg Mesh"].Sparkles
local rs = game.ReplicatedStorage

local function setTemplateEquipped()
	for i,v in pairs(scrollingFrame:GetChildren()) do
		if v:FindFirstChild("Equipped") then
			v.Equipped.Text = "Unequipped"
			v.Equipped.TextColor3 = Color3.fromRGB(255,0,0)
		end
	end
	template.Equiped.Text = "Equipped"
	template.Equiped.TextColor3 = Color3.fromRGB(0,255,0)
end

local function addToFrame(pet, player)
	local newTemplate = template:Clone()
	newTemplate.Name = pet.Name
	newTemplate.petName.Text = pet.Name
	newTemplate.Parent = scrollingFrame
	newTemplate.Visible = true
	local camera = Instance.new("Camera")
	local newPet = pet:Clone()
	newPet.Parent = newTemplate.ViewportFrame
	camera.CFrame = CFrame.new(newPet.PrimaryPart.Position + (newPet.PrimaryPart.CFrame.LookVector * 3), newPet.PrimaryPart.Position)
	camera.Parent = newTemplate.ViewportFrame
	newTemplate.ViewportFrame.CurrentCamera = camera
	buttonConnection[#buttonConnection+1] = newTemplate.MouseButton1Click:Connect(function()
		if newTemplate.Equiped.Text == "Equipped" then
			rs.unequipPet:FireServer(pet.Name)
			rs["buncha remote events for no reason"].RemoteEvent:FireServer(buttonConnection[#buttonConnection+1])
			newTemplate.Equiped.Text = "Unequipped"
			newTemplate.Equiped.TextColor3 = Color3.fromRGB(255,0,0)
		else
			rs.equipPet:FireServer(pet.Name)
			setTemplateEquipped(newTemplate)
			rs["buncha remote events for no reason"].r2:FireServer(buttonConnection[#buttonConnection+1])
		end
	end)
	rs["buncha remote events for no reason"].r3:FireServer(player, newTemplate)
end

game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect(function (pet)
	addToFrame(pet)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = studio.CameraPart.CFrame
	wait(1.5)
	for i = 1,50,1 do
		studio["Egg Mesh"].Size = studio["Egg Mesh"].Size + Vector3.new(0.1,0.1,0.1)
		wait(0.01)
	end
	local explosion = Instance.new("Explosion")
	explosion.BlastRadius = 10
	explosion.BlastPressure = 0
	explosion.Position = studio["Egg Mesh"].Position
	explosion.ExplosionType = Enum.ExplosionType.NoCraters
	explosion.DestroyJointRadiusPercent = 0
	explosion.Parent = studio["Egg Mesh"]
	studio["Egg Mesh"].Transparency = 1
	local petClone = pet:Clone()
	for i,v in pairs(petClone:GetChildren()) do
		if v:IsA("ParticleEmitter") then
			v.Enabled = true
		end
	end 
	sparkles.Enabled = false
	petClone:SetPrimaryPartCFrame(CFrame.new(studio["Egg Mesh"].Position, studio.CameraPart.Position))
	petClone.Parent = studio
	petClone.PrimaryPart.Position = Vector3.new(-14.382, -8.112, -605.565)
	petClone.PrimaryPart.Anchored = true
	local tweenInfo = TweenInfo.new(
		2,
		Enum.EasingStyle.Bounce,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local TweenService = game:GetService("TweenService")
	local targetVector = petClone.PrimaryPart.Position + (petClone.PrimaryPart.CFrame.lookVector * 5) + Vector3.new(0,0.75,0)
	local lookVector = petClone.PrimaryPart.Position
	local targetCframe = CFrame.new(targetVector, lookVector)
	local propsToTween = { CFrame = targetCframe }
	local tween  = TweenService:Create(camera, tweenInfo, propsToTween)
	tween:Play()
	wait(5)
	for i,v in pairs(petClone:GetChildren()) do
		if v:IsA("ParticleEmitter") then
			v.Enabled = false
		end
	end 
	camera.CameraType = Enum.CameraType.Custom
	studio["Egg Mesh"].Transparency = 0
	studio["Egg Mesh"].Size = Vector3.new(4.732, 6, 4.732)
	petClone:Destroy()
	sparkles.Enabled = true
end)

If you can help then thank you so much! your answer will be accepted so we both get reputation :)

1 answer

The problem is that when you use :FireServer() it automatically uses the player on the client that is firing the server as argument 1. What you are doing is firing the event and providing the player yourself which is messing up your variables when you make it to the server script (if that doesn't make sense leave a comment and I'll explain it a bit better). A working script would look like this:

local camera = workspace.Camera
local studio = workspace.Studio
local template = script.Parent.Pets.ScrollingFrame.Template
local scrollingFrame = script.Parent.Pets.ScrollingFrame
local buttonConnection = {}
local sparkles = studio["Egg Mesh"].Sparkles
local rs = game.ReplicatedStorage

local function setTemplateEquipped()
    for i,v in pairs(scrollingFrame:GetChildren()) do
        if v:FindFirstChild("Equipped") then
            v.Equipped.Text = "Unequipped"
            v.Equipped.TextColor3 = Color3.fromRGB(255,0,0)
        end
    end
    template.Equiped.Text = "Equipped"
    template.Equiped.TextColor3 = Color3.fromRGB(0,255,0)
end

local function addToFrame(pet, player)
    local newTemplate = template:Clone()
    newTemplate.Name = pet.Name
    newTemplate.petName.Text = pet.Name
    newTemplate.Parent = scrollingFrame
    newTemplate.Visible = true
    local camera = Instance.new("Camera")
    local newPet = pet:Clone()
    newPet.Parent = newTemplate.ViewportFrame
    camera.CFrame = CFrame.new(newPet.PrimaryPart.Position + (newPet.PrimaryPart.CFrame.LookVector * 3), newPet.PrimaryPart.Position)
    camera.Parent = newTemplate.ViewportFrame
    newTemplate.ViewportFrame.CurrentCamera = camera
    buttonConnection[#buttonConnection+1] = newTemplate.MouseButton1Click:Connect(function()
        if newTemplate.Equiped.Text == "Equipped" then
            rs.unequipPet:FireServer(pet.Name)
            rs["buncha remote events for no reason"].RemoteEvent:FireServer(buttonConnection[#buttonConnection+1])
            newTemplate.Equiped.Text = "Unequipped"
            newTemplate.Equiped.TextColor3 = Color3.fromRGB(255,0,0)
        else
            rs.equipPet:FireServer(pet.Name)
            setTemplateEquipped(newTemplate)
            rs["buncha remote events for no reason"].r2:FireServer(buttonConnection[#buttonConnection+1])
        end
    end)
    rs["buncha remote events for no reason"].r3:FireServer(newTemplate)
end

game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect(function (pet)
    addToFrame(pet)
    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = studio.CameraPart.CFrame
    wait(1.5)
    for i = 1,50,1 do
        studio["Egg Mesh"].Size = studio["Egg Mesh"].Size + Vector3.new(0.1,0.1,0.1)
        wait(0.01)
    end
    local explosion = Instance.new("Explosion")
    explosion.BlastRadius = 10
    explosion.BlastPressure = 0
    explosion.Position = studio["Egg Mesh"].Position
    explosion.ExplosionType = Enum.ExplosionType.NoCraters
    explosion.DestroyJointRadiusPercent = 0
    explosion.Parent = studio["Egg Mesh"]
    studio["Egg Mesh"].Transparency = 1
    local petClone = pet:Clone()
    for i,v in pairs(petClone:GetChildren()) do
        if v:IsA("ParticleEmitter") then
            v.Enabled = true
        end
    end 
    sparkles.Enabled = false
    petClone:SetPrimaryPartCFrame(CFrame.new(studio["Egg Mesh"].Position, studio.CameraPart.Position))
    petClone.Parent = studio
    petClone.PrimaryPart.Position = Vector3.new(-14.382, -8.112, -605.565)
    petClone.PrimaryPart.Anchored = true
    local tweenInfo = TweenInfo.new(
        2,
        Enum.EasingStyle.Bounce,
        Enum.EasingDirection.Out,
        0,
        false,
        0
    )
    local TweenService = game:GetService("TweenService")
    local targetVector = petClone.PrimaryPart.Position + (petClone.PrimaryPart.CFrame.lookVector * 5) + Vector3.new(0,0.75,0)
    local lookVector = petClone.PrimaryPart.Position
    local targetCframe = CFrame.new(targetVector, lookVector)
    local propsToTween = { CFrame = targetCframe }
    local tween  = TweenService:Create(camera, tweenInfo, propsToTween)
    tween:Play()
    wait(5)
    for i,v in pairs(petClone:GetChildren()) do
        if v:IsA("ParticleEmitter") then
            v.Enabled = false
        end
    end 
    camera.CameraType = Enum.CameraType.Custom
    studio["Egg Mesh"].Transparency = 0
    studio["Egg Mesh"].Size = Vector3.new(4.732, 6, 4.732)
    petClone:Destroy()
    sparkles.Enabled = true
end)

Hope I helped!

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