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

Why won't this remote event appear online? -Updated script- Still broken!

Yes I've read https://scriptinghelpers.org/blog/it-works-in-studio-but-not-online

When this script is activated, It should be creating a remote event which is then fired, creating a new character for the player to use. However, when I test this on a server, the remote event returns nil.

--Edit-- Now the event just isn't created

Inside of a Server Script





wait(.1)

while not player do
	wait()
	 player = game.Players:GetPlayerFromCharacter(script.Parent)
end
	
	function onSpawn()
	local char = game.ReplicatedStorage["New Player"]:Clone()
	local SpawnLocation = game.Workspace.SpawnLocation2
	char.Parent = workspace
	char.Name = player.Name
	char:MoveTo(SpawnLocation.Position)
	
	local prevChar = player.Character
	wait()
	player.Character = char
	prevChar:Destroy()
	
	if char:FindFirstChild("Humanoid") then
	char.Humanoid:Destroy()
	end
	local human = Instance.new("Humanoid", char)
	char.Archivable = false
	human.WalkSpeed = 8

	wait(1)

	human.Died:connect(function()
	wait(1)
		onSpawn()
		wait(.01)
	player.Character.Humanoid.Running:connect(onGround)

	
	end)
	
	--Player Values
	local move_left = false
	local move_right = false
	local already_ran = false
	local grounded = false
	local idleAnimation = Instance.new("Animation")
	idleAnimation.AnimationId = "rbxassetid://317651678"
	local runningAnimation = Instance.new("Animation")
	runningAnimation.AnimationId = "rbxassetid://319211805"
	local R2 = Instance.new("Animation")
	R2.AnimationId = "rbxassetid://312976450"
	local I2 = Instance.new("Animation")
	I2.AnimationId = "rbxassetid://313623015"
	local J = Instance.new("Animation")
	J.AnimationId = "rbxassetid://326922088"
		
	function playAnimation(parent)
		local AnimTrack = player.Character.Humanoid:LoadAnimation(parent)
		AnimTrack:Stop()
		wait(.01)
		AnimTrack:Play()
	end
	
	function onGround(speed)
		if grounded == false then
			grounded = true
		end
		if speed > 1 --and player.PlayerGui.SwordPlaySystemMK2.CombatStage.Value == ("Offensive")

			 then
			
			if already_ran == false then
				already_ran = true
				playAnimation(runningAnimation)
				
			end
			
				--elseif  speed > 1 and player.PlayerGui.SwordPlaySystemMK2.CombatStage.Value == ("Idle") then
					--if already_ran == false then
						--already_ran = true
						--playAnimation(R2)
				
					
		
		elseif speed > 0 and already_ran == true --and player.PlayerGui.SwordPlaySystemMK2.CombatStage.Value == ("Offensive") 
			then
			already_ran = false
			playAnimation(idleAnimation)
			
			--elseif speed > 0 and already_ran == true and player.PlayerGui.SwordPlaySystemMK2.CombatStage.Value == ("Idle")  then
			--already_ran = false
			--playAnimation(I2)
			
		
			
				end
			end
		end

 event = Instance.new("RemoteEvent") -- creates the event object
	event.Parent = game.ReplicatedStorage -- puts the event into the ReplicatedStorage
	event.Name = "ServerEvent" -- giving a name to the event so we can fire it specifically elsewhere

event.OnServerEvent:connect(function() -- define the function that will be called when the event is fired	
onSpawn()

	player.Character.Humanoid.Running:connect(onGround)
	game.Workspace.BasePlate.BrickColor = BrickColor.Random() 
end)

Inside of a Local Script within a GUI button

local player = game:GetService("Players").LocalPlayer 
script.Parent.MouseButton1Click:connect(function()
local S = game.ReplicatedStorage.SpawnScript:Clone()
S.Parent = player.Character
S.Disabled = false
wait(1)
local e = game.ReplicatedStorage:WaitForChild("ServerEvent")
e:FireServer()
end)


Thanks in advance for any help.

2 answers

✓ Accepted answer

In line 3 of your local script, game.ReplicatedStorage.SpawnScript:Clone() will not properly replicate to the server when its filtering enabled.

Instead of creating the RemoteEvent from a script (just like in line 97 of the first script), just create the RemoteEvent in ReplicatedStorage in Studio to begin with and rename it as "ServerEvent".

In a Server Script in ServerScriptService:
function onSpawn(player)
    local char = game.ReplicatedStorage["New Player"]:Clone()
    local SpawnLocation = game.Workspace.SpawnLocation2
    char.Parent = workspace
    char.Name = player.Name
    char:MoveTo(SpawnLocation.Position)

    local prevChar = player.Character
    wait()
    player.Character = char
    prevChar:Destroy()

    if char:FindFirstChild("Humanoid") then
        char.Humanoid:Destroy()
    end
	
    local human = Instance.new("Humanoid", char)
    char.Archivable = false
    human.WalkSpeed = 8

    wait(1)

    human.Died:connect(function() --  are you sure about this?
        wait(1)
        onSpawn(player)
        wait(.01)
		player.Character.Humanoid.Running:connect(onGround)
    end)

    --Player Values
    local move_left = false
    local move_right = false
    local already_ran = false
    local grounded = false
    local idleAnimation = Instance.new("Animation")
    idleAnimation.AnimationId = "rbxassetid://317651678"
    local runningAnimation = Instance.new("Animation")
    runningAnimation.AnimationId = "rbxassetid://319211805"
    local R2 = Instance.new("Animation")
    R2.AnimationId = "rbxassetid://312976450"
    local I2 = Instance.new("Animation")
    I2.AnimationId = "rbxassetid://313623015"
    local J = Instance.new("Animation")
    J.AnimationId = "rbxassetid://326922088"

    function playAnimation(parent) 
        local AnimTrack = player.Character.Humanoid:LoadAnimation(parent)
        AnimTrack:Stop()
        wait(.01)
        AnimTrack:Play()
    end

    function onGround(speed)
        if grounded == false then
            grounded = true
        end
        if speed > 1 then
            if already_ran == false then
                already_ran = true
                playAnimation(runningAnimation)
            end
        elseif speed > 0 and already_ran == true then
            already_ran = false
            playAnimation(idleAnimation)
        end
    end

    player.Character.Humanoid.Running:connect(onGround) -- this should probably be inside
end

local event = game.ReplicatedStorage:WaitForChild("ServerEvent") -- make sure the event in in ReplicatedStorage
event.OnServerEvent:connect(function(player) -- OnServerEvent automatically passes the player who fired it as the first argument.
    onSpawn(player)
    game.Workspace.BasePlate.BrickColor = BrickColor.Random() 
end)

In a localscript

local player = game:GetService("Players").LocalPlayer 
script.Parent.MouseButton1Click:connect(function()
    local e = game.ReplicatedStorage:WaitForChild("ServerEvent")
    e:FireServer()
end)

You're most likely firing the event before it is created. I would change line 7 of your LocalScript to read

game.Workspace:WaitForChild("ServerEvent"):FireServer()

1 comment

0

The issue is, the event still doesn't seem to be created at all.

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