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

Instance doesn't work when I try to use it in remote event. Any Ideas?


Ok so I have a local script that plays an animation then calls a remote event inside the local script. The remote event starts a server script also inside the local script which anchors every body part of the player then I have an instance that is supposed to add a part in the player's torso but the part does not show not even in the character torso.

Local Script:

local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local CreepyAnim = Instance.new("Animation")
CreepyAnim.AnimationId = "rbxassetid://05095167054"
local remoteEvent = script:WaitForChild("RemoteEvent")

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.L then
		local loadanim = player.Character.Humanoid:LoadAnimation(CreepyAnim)
		loadanim:Play()
		wait(1)
		remoteEvent:FireServer(player)
	end
end)

Server Script inside the local script activated by the remote event:

script.Parent.RemoteEvent.OnServerEvent:Connect(function(Player)
	Player.Character.Head.Anchored = true
	Player.Character.UpperTorso.Anchored = true
	Player.Character.LowerTorso.Anchored = true
	Player.Character.RightUpperArm.Anchored = true
	Player.Character.RightLowerArm.Anchored = true
	Player.Character.RightHand.Anchored = true
	Player.Character.LeftUpperArm.Anchored = true
	Player.Character.LeftLowerArm.Anchored = true
	Player.Character.LeftHand.Anchored = true
	Player.Character.RightUpperLeg.Anchored = true
	Player.Character.RightLowerLeg.Anchored = true
	Player.Character.RightFoot.Anchored = true
	Player.Character.LeftUpperLeg.Anchored = true
	Player.Character.LeftLowerLeg.Anchored = true
	Player.Character.LeftFoot.Anchored = true
	print("ANCHORED!")
	local Beam = Instance.new("Part")
	Beam.Parent = Player.Character.UpperTorso
	Beam.Shape = "Cylinder"
	Beam.Orientation = Vector3.new(0, 0, 90)
	Beam.Size = Vector3.new(4,1,1)
	print("Beam Initiated")
end)

Thank You in advance

3 comments

0

Where is the local script stored?

0

starter pack

0

You don't have to fire the player. FireServer() does that automatically by the way.

2 answers

✓ Accepted answer

You can't use a remote inside a local script like that because of the way roblox loads it. A LocalScript is only loaded on the client so the server can't see it. Even if the script has a direct path to the event it will still only load on the client making it the same as a LocalScript. If you want to preform this action put the event in ReplicatedStorage and the script in ServerScriptService. Inside the script you can find the event by putting a variable like so:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Event = ReplicatedStorage:WaitForChild("CreepyAnimation") --Change this to the actual name of your event

Just a little tip as well. If you want to anchor every body part and not have to worry about missing one you might want to a for I, V in pairs do loop like this:

local Character = Player.Character
for I, V in pairs(Character:GetChildren()) do
	if V:IsA("MeshPart") then
		V.Anchored = true
	end
end
--or you could anchor the humanoidrootpart which will also stop the character from moving.
Character:WaitForChild("HumanoidRootPart").Anchored = true

1 comment

0

Thanks for telling me how to anchor all parts

So you pretty much got it correct except for a few things. Remote events should be placed in replicated storage always.

Replicated storage is the only place in the game that can communicate to the client and the server, so it makes sense to have it replicated storage right?

Also when you FireServer(player), it actually should be FireServer() because it sends the player as an invisible parameter to the OnServerEvent. You would keep player in the OnServerEvent:Connect(function(player) end) though.

So to fix your code you would put one Remote Event named any name. So in this case you named yours RemoteEvent so you will use that. I recommend changing the name to suit what you want it to send. So I would change the RemoteEvents name to AnimationPartBLAH lol. And I would put the remote event inside Replicated Storage somewhere.

Now for your code:

The Local script would look like this if we were using my remote event named AnimationPartBLAH:

local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local CreepyAnim = Instance.new("Animation")
CreepyAnim.AnimationId = "rbxassetid://05095167054"
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("AnimationPartBLAH")

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.L then
        local loadanim = player.Character.Humanoid:LoadAnimation(CreepyAnim)
        loadanim:Play()
        wait(1)
        remoteEvent:FireServer()
    end
end)

The Server Script would look like this:

game.ReplicatedStorage.AnimationPartBLAH.OnServerEvent:Connect(function(Player)
    Player.Character.Head.Anchored = true
    Player.Character.UpperTorso.Anchored = true
    Player.Character.LowerTorso.Anchored = true
    Player.Character.RightUpperArm.Anchored = true
    Player.Character.RightLowerArm.Anchored = true
    Player.Character.RightHand.Anchored = true
    Player.Character.LeftUpperArm.Anchored = true
    Player.Character.LeftLowerArm.Anchored = true
    Player.Character.LeftHand.Anchored = true
    Player.Character.RightUpperLeg.Anchored = true
    Player.Character.RightLowerLeg.Anchored = true
    Player.Character.RightFoot.Anchored = true
    Player.Character.LeftUpperLeg.Anchored = true
    Player.Character.LeftLowerLeg.Anchored = true
    Player.Character.LeftFoot.Anchored = true
    print("ANCHORED!")
    local Beam = Instance.new("Part")
    Beam.Parent = Player.Character.UpperTorso
    Beam.Shape = "Cylinder"
    Beam.Orientation = Vector3.new(0, 0, 90)
    Beam.Size = Vector3.new(4,1,1)
    print("Beam Initiated")
end)

4 comments

0

He answered first and provided more to offer so I would accept his answer over mine.

0

He as in you or he as in Narunzo

0

You both gave me the answers Narunzo told me how to anchor all parts and you told me how to fix my remote event problem so thank you to both of you

0

Although this is a good answer this doesn't fix my instancing problem

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