Script Working Very Weirdly

Hey so this is my script i have for a quest in my game

it works perfectly fine but if theres more than one player in the server then it doesnt destroy the crate after completing the quest, it still completes the quest and gives u the money and exp but it just wont destroy the box on ur back unless ur the only one in the server

IT PRINTS “DESTROYED CRATE” OR WTV REGARDLESS WHICH IS WHY IM CONFUSED

local rps = game:GetService("ReplicatedStorage")
local rs = game:GetService("RunService")
local mainmodule = require(rps:WaitForChild("MainModule"))
local questFolder = rps:WaitForChild("QuestStuff")

local QuestInfoModule = {}
-- WE LOVE FAE <3
function QuestInfoModule.Fae(player)
	local questRewards = {
		Exp = 100,
		Credits = 50
	}

	local char = player.Character
	local hrp = char:WaitForChild("HumanoidRootPart")
	local humanoid = char:WaitForChild("Humanoid")

	local crate = questFolder.Crate:Clone()
	crate.Name = player.Name .. "_Crate"
	crate.CFrame = hrp.CFrame
	crate.Parent = workspace.debrisFolder

	local torso = char:FindFirstChild("Torso") or char:FindFirstChild("UpperTorso")
	if not torso then return end

	local crateweld = Instance.new("Weld")
	crateweld.Name = player.Name .. "_CrateWeld"
	crateweld.Part0 = torso
	crateweld.Part1 = crate
	crateweld.C0 = CFrame.new(0, 0, 2.2)
	crateweld.Parent = crate 
	crate:SetNetworkOwner(nil)

	local marker = questFolder.Marker:Clone()
	marker.Name = player.Name .. "'s Marker"
	marker.Position = Vector3.new(-3729.816, 8.132, 3906.279)
	marker.Parent = workspace.debrisFolder

	questFolder.QuestRemote:FireClient(player)

	local connections = {}

	-- MEMORY LEAK FIX YAY :3
	local function endQuest(arg)
		if arg then
			if player:FindFirstChild("data") then
				local data = player.data
				data.Credits.Value += questRewards.Credits
				mainmodule.GiveExp(player, questRewards.Exp)
			end
		end

		if crateweld and crateweld.Parent then
			crateweld:Destroy()
		end

		if crate and crate:IsDescendantOf(workspace) then
			crate:Destroy()
			print("Crate destroyed for", player.Name)
		end

		if marker and marker:IsDescendantOf(workspace) then
			marker:Destroy()
		end

		for _, conn in pairs(connections) do
			if conn.Connected then
				conn:Disconnect()
			end
		end
	end

	table.insert(connections, humanoid.Died:Connect(function()
		endQuest()
	end))

	table.insert(connections, char.AncestryChanged:Connect(function(_, parent)
		if not parent then
			endQuest()
		end
	end))

	if game.Players:FindFirstChild(player.Name) then
		table.insert(connections, player.AncestryChanged:Connect(function(_, parent)
			if not parent then
				endQuest()
			end
		end))
	end

	table.insert(connections, rs.Heartbeat:Connect(function()
		if (marker.Position - hrp.Position).Magnitude < 5 then
			if not player:GetAttribute("Fae") then return end
			mainmodule.RemoveAttribute(player, "Fae")
			mainmodule.RemoveAttribute(player, "DoingQuest")
			endQuest("complete")
			questFolder.SoundRemote:FireClient(player)
		end
	end))
end

return QuestInfoModule

1 Like

bruh… i fixed it right after posting this (i tried for hours) the issue was the script was in guiservice or wtv so it was like diuplicating??? idk sum like that anyways its fixed

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.