Need help with This, Please

So, I made a LocalScript in Workspace to fire a RemoteEvent in ReplicatedStorage to change the players character when the character joins, here is an example:

local player = game.Players.LocalPlayer
local Event = game.ReplicatedStorage.MorphEvent
local Morph = Event.Parent.Characters.Morph
player.CharacterAdded:Wait()
Event:FireServer(Morph)

Please Tell me if i did anything wrong.

2 Likes

LocalScripts don’t run in Workspace. Parent it to something like PlayerGui.

Also, I recommend using Players.CharacterAdded in a Players.PlayerAdded event so that you can make your code format easier to understand and practically performance wiser.

1 Like

it’s still not working.
maybe it has something to do with my Event Script:

local Storage = game.ReplicatedStorage

Storage.MorphEvent.OnServerEvent:Connect(function(Player,Morph: Morph)
	local Character = Player.Character
	local HumanoidRootPart = Character:WaitForChild("Head")
	local MorphClone = Morph:Clone()
	
	HumanoidRootPart.Anchored = true
	
	wait(1)
	
	MorphClone.Name = Player.Name .. ""
	MorphClone:WaitForChild("Head").Position = HumanoidRootPart.Position
	MorphClone.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Viewer
	local ActivateBackpack = Player.Backpack:GetChildren()
	local Folder = Instance.new("Folder")
	Folder.Parent = game.ServerStorage
	Folder.Name = Player.Name
	for i,Tool in pairs(ActivateBackpack) do
		Tool:Clone().Parent = Folder
	end
	local success, err = pcall(function()
		Character:FindFirstChildOfClass("Tool"):Clone().Parent = MorphClone
	end)
	Player.Character = MorphClone
	local MorphBackpack = Player.Backpack:GetChildren()
	MorphClone.Parent = workspace
	MorphClone.Animate.Disabled = false
	
	for i,Tool in pairs(MorphBackpack) do
		Tool:Destroy()
	end
	for i,Tool in pairs(game.ServerStorage:WaitForChild(Player.Name):GetChildren()) do
		Tool:Clone().Parent = Player.Backpack
	end
	game.ServerStorage:WaitForChild(Player.Name):Destroy()
	for i,Part in pairs(MorphClone:GetChildren()) do
		if Part.ClassName == "Part" or Part.ClassName == "UnionOperation" or Part.ClassName == "MeshPart" then
			Part.Anchored = false
		end
	end
end)

Morph is not a valid type.

Where’d you parent your LocalScript?
Again,

1 Like

are you sure HumanoidRootPart is supposed to be the player’s head?
Also you should be using task.wait() as its more precise and less laggy than wait()

1 Like

The HumanoidRootPart won’t work if i’m trying to put the morphclone in the same position as the original character

1 Like

Morph is my own Variable thing

Event:FireServer(Morph)
2 Likes

Yes, but using : you tell the code that it’s a DataType, where Morph doesn’t exist as a Roblox/Lua DataType.

it still works the same way… @SomeFedoraGuy

Why are you using local script for this anyways

the localscript’s parent is startergui

Well you can acces players gui with server script

1 Like

localscripts worked for events like

Button.Activated:Connect(function()
   Event:FireServer()
end)

That will also work in server script also, you got any error in logs?

there is Nothing in the logs. :frowning_face: :slightly_frowning_face:

Button.MouseButton1Down:Connect(function()
   Event:FireServer()
end)
1 Like