Do I need a remote function to make this work?

Hello! I’m making a crafting system but this is in a server script. The backpack can only be accessed by a local script. So do I need a remote function? I’m new to scripting(and remote events) so I’m really confused what to do.

I also need the checkBackPack function to activate when someones presses a gui button, how do I do that?

local ingredients = {
-- there was stuff here, but I removed it for this post
}

local elementcolor = Color3.fromHSV(0.485222, 0.457603, 0.771817) -- replace the H and S values to the correct power color


local function resetProperties()
	game.Lighting.FuseMachineEffect.Enabled = false
	game.Lighting.FuseMachineEffect2.Enabled = false
	game.Lighting.BlurFuseMachineEffect.Enabled = false
	game.Lighting.FuseBurstEffect.Enabled = false
	script.Parent.Basket.Attachment.Particles.Enabled = false
	script.Parent.Basket.Attachment2.PlushiesBasic.Enabled = false
	script.Parent.Basket.Attachment2.PlushiesWinged.Enabled = false
	script.Parent.Basket.Orientation = Vector3.new(0,0,0)
	script.Parent.YarnBall1.Orientation= Vector3.new(0,0,0)
	script.Parent.YarnBall2.Orientation= Vector3.new(0,0,0)
	script.Parent.PowerBeam.Color = elementcolor
	script.Parent.PowerBeam2.Color = elementcolor
	script.Parent.PowerFluid.Color = elementcolor
	script.Parent.Top.Orientation = Vector3.new(0,0,0)

end

local function playAnimation()
	resetProperties()
	-- this changes the whole lighting effects
	game.Lighting.FuseMachineEffect.Enabled = true
	game.Lighting.FuseMachineEffect2.Enabled = true
	game.Lighting.BlurFuseMachineEffect.Enabled = true
	--this activates the plushie particles
	script.Parent.Basket.Attachment2.PlushiesBasic.Enabled = true 
	script.Parent.Basket.Attachment2.PlushiesWinged.Enabled = true
	wait(1.2)-- change this to how long you want the plushie thrown in basket effect to last
	script.Parent.Basket.Attachment2.PlushiesBasic.Enabled = false
	script.Parent.Basket.Attachment2.PlushiesWinged.Enabled = false
	wait(1)
	game.Lighting.FuseMachineEffect.Enabled = false
	game.Lighting.FuseMachineEffect2.Enabled = false
	game.Lighting.BlurFuseMachineEffect.Enabled = false
	game.Lighting.FuseBurstEffect.Enabled = true
	script.Parent.Thump:Play()
	script.Parent.Wind:Play()
	script.Parent.Mysterious:Play()
	for count = 0,130 do
		-- spins the yarn balls and basket(as well as enable the particles)
		script.Parent.Basket.Attachment.Particles.Enabled = true
		script.Parent.Basket.CFrame= script.Parent.Basket.CFrame * CFrame.fromEulerAnglesXYZ(0,0.2 ,0)
		script.Parent.YarnBall1.CFrame= script.Parent.YarnBall1.CFrame * CFrame.fromEulerAnglesXYZ(0,0.5 ,0)
		script.Parent.YarnBall2.CFrame= script.Parent.YarnBall2.CFrame * CFrame.fromEulerAnglesXYZ(0,0.5 ,0)
		script.Parent.Top.CFrame= script.Parent.Top.CFrame * CFrame.fromEulerAnglesXYZ(0,0.1 ,0)
		-- randomizes the light value of the colors of the power fluid
		script.Parent.PowerBeam.Color = Color3.fromHSV(0, 0, math.random(0.1,1))
		script.Parent.PowerBeam2.Color = Color3.fromHSV(0, 0, math.random(0.1,1))
		script.Parent.PowerFluid.Color = Color3.fromHSV(0, 0, math.random(0.1,1))

		wait(0.02)
	end
	resetProperties()
end


-- Fusing


local MagicPlushie = game.ServerStorage["Sibble Plushies"]["Neutral Magic Plushie"]
local Backpack = game.Players.LocalPlayer:WaitForChild("Backpack")
local ingredients = {"Red Basic Plushie","Red Winged Plushie","Blue Basic Plushie","Blue Winged Plushie", "Green Basic Plushie","Green Winged Plushie", "White Basic Plushie", "White Winged Plushie","Yellow Basic Plushie","Yellow Winged Plushie"}

local function checkBackpack(ing)
	if MagicPlushie and not Backpack:FindFirstChild(MagicPlushie) then
		local hasIngredients = true

		for i,v in pairs (ing) do
			if not Backpack:FindFirstChild(v) then
				hasIngredients = false 
				print("Player Doesnt have ingredients")
				break 
			end
		end

		if hasIngredients == true then
			print("Player Has Ingredients")
		end

	end
end


game.ReplicatedStorage.FuseNeutral.OnServerEvent:Connect(function()
	if MagicPlushie and not Backpack:FindFirstChild(MagicPlushie) then
		checkBackpack(ingredients)
	end
end)


wait(4)
checkBackpack(ingredients)

1 Like

The server can also access the player’s backpack! But what is it you are trying to attempt I see no clear indication of what you are trying to do??

3 Likes

You can use either a remote event or a remote function. Remote events are asynchronous, while remote functions are synchronous and if the server fires one it will wait until the client returns something to it.

(Also, the backpack can be accessed on the server too. You dont need any remotes for it.)

2 Likes

I assume he is using a custom backpack.

Ok I just read the code and you are right. I will edit my previous comment.

3 Likes

Well it says "attempt to index nil with WaitForChild(“Backpack”)

ps: I replied to the other person with a better explanation of what I’m trying to achieve.

1 Like

It doesn’t think the backpack exists. And I know its really confusing lol.

It’s basically a machine that lets you fuse the required tools you have into a new tool. So Its sorta like a crafting system. I need it to access the backpack so it can put the tool in it, as well as see if the player has the needed ingredients(thats what the table is).
The script activates when you press a guibutton that pops up once you go near the machine. However the popup is inside a local script so the MouseButton1Click can’t work with this server script. So I want to know how to make that button work with this script, as well as see why it can’t find the backpack.

I apologize for not responding I had to quickly make this post due to school related things. So I didn’t really spend time explaining what was going on.

1 Like

You can’t get the LocalPlayer from the server, that’s what causes the error.

2 Likes

Then how do I access the backpack?

1 Like

When you fire to the server, it sends the player in the remote event and it will always be the first parameter

game.ReplicatedStorage.FuseNeutral.OnServerEvent:Connect(function(player) -- <<< player here
	local Backpack = player.Backpack
end)
2 Likes

K, so I think the only problem now is that I don’t know how to activate this event via guibutton. Could you help me?

1 Like