Cannot Create Part Inside Remote Event Scripts

I want to make a script that will create new part when a remote is fired. But It doesn’t even create the part (or maybe, it doesn’t even go to The Workspace, I don’t know… What I know is, no new part is created in The Workspace). But when I put the part creation lines outside the Remote FireServer Function, It works normally.

Here is my script:

local RS = game:GetService("ReplicatedStorage");
local remote = RS:FindFirstChild("Attack");

local TS = game:GetService("TweenService");

function onAction(player,char,power,action)
	if power == 1 then
		local hum = char:FindFirstChild("Humanoid");
		if action == 0 then
			print("ABC");
			local CBlast = Instance.new("Part");
			CBlast.Shape = "Ball";
			CBlast.Name = "CBlast";
			CBlast.Color = Color3.new(1,1,1);
			CBlast.Material = "Neon";
			CBlast.Size = Vector3.new(0.1,0.1,0.1);
			CBlast.Anchored = true;
			CBlast.Transparency = 0.5;
			CBlast.CFrame = char.HumanoidRootPart.CFrame;
			CBlast.Parent = char;
			hum.WalkSpeed = 0;
			local Tween1 = TS:Create(CBlast,TweenInfo.new(1),{
				Size = Vector3.new(5,5,5);
			});
			Tween1:Play();
			CBlast:Destroy();
			hum.WalkSpeed = 16;
		elseif action == 1 then
				
		end
	end
end

remote.OnServerEvent:Connect(onAction);

The problem is not in the if statements, because it outputs “ABC”.

How do I fix it?

Client Code?

Or have you not scripted the elseif statement

It looks like you are not waiting for the tween to complete before destroying the part.

Add this right after Tween1:Play();:

Tween1.Completed:Wait();
1 Like

Oh I see… That’s the problem… Thank you :slight_smile:
(I can’t believe that I forgot something important like that :disappointed_relieved:)