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

Expected 'end' (to close 'then' at line 52), got <eof>?

Expected 'end' (to close 'function' at line 52), got ; did you forget to close 'then' at line 103?

local function equipPet(Player,pet)
	
	local character = Player.Character
	
	if pet ~= nil and character ~= nil then
		
		if character:FindFirstChild(Player.Name.."'s Pet") then character[Player.Name.."'s Pet"]:Destroy() end
		
		if character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then 
			character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy() 
		end
		
		pet.Name = Player.Name.."'s Pet"
		
		pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)
		
		local modelSize = pet.PrimaryPart.Size
		
		local attachmentCharacter = Instance.new("Attachment")
		attachmentCharacter.Visible = false
		attachmentCharacter.Name = "attachmentCharacter"
		attachmentCharacter.Parent = character.HumanoidRootPart
		attachmentCharacter.Position = Vector3.new(1,1,0) + modelSize
		
		local attachmentPet = Instance.new("Attachment")
		attachmentPet.Visible = false
		attachmentPet.Parent = pet.PrimaryPart
		
		local alignPosition = Instance.new("AlignPosition")
		alignPosition.MaxForce = 25000
		alignPosition.Attachment0 = attachmentPet
		alignPosition.Attachment1 = attachmentCharacter
		alignPosition.Responsiveness = 25
		alignPosition.Parent = pet
		
		local alignOrientation = Instance.new("AlignOrientation")
		alignOrientation.MaxTorque = 25000
		alignOrientation.Attachment0 = attachmentPet
		alignOrientation.Attachment1 = attachmentCharacter
		alignOrientation.Responsiveness = 25
		alignOrientation.Parent = pet
		
		pet.Parent = character
		
	end
	
end

local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("CoinsStats")

game.Players.PlayerAdded:Connect(function(Player)

	local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"

	local Currency = Instance.new("IntValue", leaderstats)
	Currency.Name = "Coins"
	Currency.Value = 0

	local inventory = Instance.new("Folder")
	inventory.Name = "PetInventory"
	inventory.Parent = Player

	local equippedPet = Instance.new("StringValue")
	equippedPet.Name = "EquippedPet"
	equippedPet.Parent = Player


	local Data = DS:GetAsync(Player.UserId)
	if Data then
		Currency.Value = Data
	
	Player.CharacterAdded:Connect(function(char)
		if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
			equipPet(Player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
		end
	end)
	
	equippedPet.Changed:Connect(function()
		if equippedPet.Value ~= nil then
			if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
				equipPet(Player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
			end
		end
	end)
	
end

game.ReplicatedStorage.EquipPet.OnServerEvent:Connect(function(player,petName)
	local pet = game.ReplicatedStorage.Pets:FindFirstChild(petName)
	
	if pet and player.PetInventory:FindFirstChild(petName) then
		player.EquippedPet.Value = petName
	end
end)

game.ReplicatedStorage.UnequipPet.OnServerEvent:Connect(function(player)
	player.EquippedPet.Value = ""
	if player.Character:FindFirstChild(player.Name.."'s Pet") then
		player.Character[player.Name.."'s Pet"]:Destroy()
	end
	if player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
		player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy()
	end
end)

4 comments

0

Its a bit hard to read your code since its a bit messy. But from what it looks like you forgot to close of a line at 52.

0

ye but I just don't know how to close it then

0

i editet it now i hope this looks better

0

I already found the issue. There is no help needed anymore

1 answer

could be this?!?

local leaderstats = Instance.new("Folder", Player)
leaderstats.Name = "leaderstats"

local Currency = Instance.new("IntValue", leaderstats)
Currency.Name = "Coins"
Currency.Value = 0

local inventory = Instance.new("Folder")
inventory.Name = "PetInventory"
inventory.Parent = Player

local equippedPet = Instance.new("StringValue")
equippedPet.Name = "EquippedPet"
equippedPet.Parent = Player


local Data = DS:GetAsync(Player.UserId)
if Data then
    Currency.Value = Data

Player.CharacterAdded:Connect(function(char)
    if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
        equipPet(Player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
    end
end)

equippedPet.Changed:Connect(function()
    if equippedPet.Value ~= nil then
        if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
            equipPet(Player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
        end
    end
end)

game.ReplicatedStorage.EquipPet.OnServerEvent:Connect(function(player,petName) local pet = game.ReplicatedStorage.Pets:FindFirstChild(petName)
game.ReplicatedStorage.UnequipPet.OnServerEvent:Connect(function(player) player.EquippedPet.Value = "" if player.Character:FindFirstChild(player.Name.."'s Pet") then player.Character[player.Name.."'s Pet"]:Destroy() end if player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter") line 103 player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy() 
end 
end
end)

1 comment

0

no this isn't it. I'm grateful you responded, I've now put the whole script down.

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