BindableEvent not working neither RemoteEvent

I had a problem.
First : I have an local script named Mmblox, which is an attempt to recreate graphics in minecraft. But working for death screen, I found out that the LoadCharacter function was not working. I tried neither many event types but neither worked. Can anybody sovle this?

Mmblox code:

--!nocheck
game.Players.LocalPlayer.CharacterAdded:Wait()
local path = game.ReplicatedStorage.block_graphics
local player = game.Players.LocalPlayer
local cam = workspace.CurrentCamera
local eventres = script.eventres
local scriptres = script.scriptres
local res = script.res
local mat = require(script.scriptres.math)
do
	tblock = mat.tblock
	sawtooth = mat.sawtooth
end


local graphic_class = {}
local item_class = {}


local graph = {}


local terrain = {}
local MCEnum = require(script.scriptres.classes)
local x : EnumItem = {}



function graph:registerItem(name : string, id : string, tool : Tool)
	local item = {}
	item.ID = id
	item.Name = name
	item.Tool = tool
	return item
end

type mc_itemObject = typeof(graph:registerItem(...))

function graph:registerBlock(regist_folder : {any}, name : string, id : string, mining_sound : Sound?,
	drops : {mc_itemObject},
	mining_sound_completed : Sound?,
	renderdata : BasePart, destroyable : boolean,
	custom_behavior : () -> ()
)
	local block = {}
	block.ID = id
	block.mining_sound = mining_sound
	block.drops = drops
	block.mining_sound_completed = mining_sound_completed
	block.render = renderdata
	block.destroyable = destroyable
	block.custom_behavior = custom_behavior
	graphic_class[block.ID] = block
	return block
end

type mc_blockObject = typeof(graph:registerBlock(...))


function graph:renderBlock(block : mc_blockObject , pos : Vector3)
	local blockw = graphic_class[block.ID].render
	if blockw then
		local x : BasePart = block.render:Clone()
		x.Parent = workspace
		x.Position = pos
		spawn(function()
			local lastsize = x.Size
			local clicked = false
			local fx = game.ReplicatedStorage.data.select:Clone()
			fx.Parent = x
			fx.Adornee = x
			fx.Visible = false
			if block.destroyable then
				local clickdetect = Instance.new("ClickDetector")
				
				clickdetect.Parent = x
				
				clickdetect.MouseClick:Connect(function()
					clicked = true
					x.CanCollide = false
					x.Transparency = 1
					for i,v in pairs(x:GetChildren()) do
						v:Destroy()
					end
					local f = game.ReplicatedStorage.data.blockdestroy:Clone()
					f.Parent = x
					f:Emit(19)
					wait(0.5)
					x:Destroy()
				end)
				
				while wait() do
					clickdetect.MouseHoverEnter:Connect(function(playerWhoHovered: Player) 
						if not clicked then
							fx.Visible = true
						end
					end)
					clickdetect.MouseHoverLeave:Connect(function(playerWhoHovered: Player) 
						if not clicked then
							fx.Visible = false
						end
					end)
				end
			end
		end)
		
		spawn(block.custom_behavior)
		return x 
	else
		error("Failed to render block")
	end
end

local deathcolor = Color3.fromRGB(255, 98, 98)
local h : Humanoid = player.Character:FindFirstChildOfClass("Humanoid")
h.Died:Connect(function() 
	local f = script.res.minecraft_death:Clone()
	local n = f.youdied
	f.Parent = player.PlayerGui
	f.TextButton.TextTransparency = 1
	f.TextLabel.Transparency = 1
	f.youdied.TintColor = Color3.fromRGB(255, 255, 255)
	game.TweenService:Create(f.youdied, TweenInfo.new(1), {TintColor = deathcolor}):Play()
	game.TweenService:Create(cam, TweenInfo.new(1), {FieldOfView = 40}):Play()
	f.youdied.Parent = game.Lighting
	game.TweenService:Create(f.TextButton, TweenInfo.new(1), {Transparency = 0}):Play()
	game.TweenService:Create(f.TextLabel, TweenInfo.new(1), {TextTransparency = 0}):Play()
	wait(1)
	f.TextButton.MouseButton1Click:Connect(function()
		f:Destroy()
		n:Destroy()
		game.TweenService:Create(cam, TweenInfo.new(1), {FieldOfView = 70}):Play()
		
		eventres:WaitForChild("Mm_Died"):Fire(player)
	end)
end)

---------------------------------------------------------------------------------------------------------------------------

local blocks = {}
blocks.Grass = graph:registerBlock(graphic_class, "Grass", "001", nil, nil, nil, path["Grass (Snowed)"], true, function() end)
blocks.Dirt = graph:registerBlock(graphic_class, "Dirt", "002", nil, nil, nil, path["Dirt"], true, function() end)
blocks.Bedrock = graph:registerBlock(graphic_class, "Bedrock", "003", nil, nil, nil, path["Bedrock"], false, function() end)
blocks.Wood = graph:registerBlock(graphic_class, "Wood", "004", nil, nil, nil, path["Wood"], false, function() end)

---------------------------------------------------------------------------------------------------------------------------

terrain.buildings = {}

---------------------------------------------------------------------------------------------------------------------------
--> terrain, graph, mat
local __X = workspace.start.Position
local current = __X
workspace.start:Destroy()

for i = 0,15 do
	for j = 0,15 do
		graph:renderBlock(blocks.Grass, current + Vector3.new(tblock(i) , 0, tblock(j)))
	end
end

current = Vector3.new(__X.X, current.Y, __X.Z)
current -= Vector3.new(0, 4, 0)

for a = 0,7 do
	for i = 0,15 do
		for j = 0,15 do
			graph:renderBlock(blocks.Dirt, current + Vector3.new(tblock(i) , 0, tblock(j)))
		end
	end
	current = Vector3.new(__X.X, current.Y, __X.Z)
	current -= Vector3.new(0, 4, 0)
end

for i = 0,15 do
	for j = 0,15 do
		graph:renderBlock(blocks.Bedrock, current + Vector3.new(tblock(i) , 0, tblock(j)))
	end
end

Mm_died script:

script.Parent.Parent.eventres:WaitForChild("Mm_Died").Event:Connect(function( player : Player) 
	print("OK")
	player:LoadCharacter()
end)

And also remember Mmblox is localscript, the Mm_Died script is legacy.
I would be happy if anyone found the issue.

Fire doesnt exist, since youre firing from the client, it would be FireServer

eventres:WaitForChild("Mm_Died"):Fire(player) -- OLD

eventres:WaitForChild("Mm_Died"):FireServer(player) -- NEW

And Event doesnt exist either, since youre connection the event from the server it would be OnServerEvent

script.Parent.Parent.eventres:WaitForChild("Mm_Died").Event:Connect(function( player : Player) 
	player:LoadCharacter()
	--OLD
end)

script.Parent.Parent.eventres:WaitForChild("Mm_Died").OnServerEvent(function(player: Player) 
	player:LoadCharacter()
	--NEW
end)

You can read more about it here:

Edit: You also dont need to add “player” if youre firing from the client because player will always be the first property by default

eventres:WaitForChild("Mm_Died"):FireServer(player) works the same as eventres:WaitForChild("Mm_Died"):FireServer() Except the first event now has 2 player properties, which isnt needed

1 Like

Erm sorry but its a BindableEvent

BindableEvents don’t allow client-server communication, use a remote event. BindableEvents only work client-client or server-server, kinda like a outside function for that type of script

I don’t need client-server communication as what i need is to make the player respawn
but it is not possible to do it on localscript

if you need the player to respawn after clicking the respawn button in your menu, youre going to need a remote to connect to the server

Fine then, ill try that. tysm then

1 Like

It works! Tysm!!!

1 Like

Wait… After the second time respawned the death GUI won’t work

like clicking the button wont work?

no
It doesnt show up whatever i try to do
The script also doesnt work whatever it saids

where is the local script located at, is it in StarterPlayerScripts ?

workspace
but it works because it is Script, but with runcontext being client

okay, since the script is in workspace that means it will only run once, which by looking at your script thats prob for the best. but cleary since it only runs once that means the humanoid variable isnt updating with the new character when respawned.

this should be a easy fix, we just have to check if the character was respawned, and if it was then we can update the variable

local h : Humanoid = player.Character:FindFirstChildOfClass("Humanoid")

player.CharacterAdded:Connect(function(Character)
	
	h = Character:FindFirstChildOfClass("Humanoid")
	
	h.Died:Once(function() -- Switched to once because the event can only be fired one time
		
		local f = script.res.minecraft_death:Clone()
		local n = f.youdied
		f.Parent = player.PlayerGui
		f.TextButton.TextTransparency = 1
		f.TextLabel.Transparency = 1
		f.youdied.TintColor = Color3.fromRGB(255, 255, 255)
		game.TweenService:Create(f.youdied, TweenInfo.new(1), {TintColor = deathcolor}):Play()
		game.TweenService:Create(cam, TweenInfo.new(1), {FieldOfView = 40}):Play()
		f.youdied.Parent = game.Lighting
		game.TweenService:Create(f.TextButton, TweenInfo.new(1), {Transparency = 0}):Play()
		game.TweenService:Create(f.TextLabel, TweenInfo.new(1), {TextTransparency = 0}):Play()
		wait(1)
		f.TextButton.MouseButton1Click:Connect(function()
			f:Destroy()
			n:Destroy()
			game.TweenService:Create(cam, TweenInfo.new(1), {FieldOfView = 70}):Play()

			eventres:WaitForChild("Mm_Died"):Fire(player)
		end)
		
	end)
	
end)

Let me know if this fixes it

sorry it did not work since additionally it breaks the script structures

Sorry, Try this one

h.Died:Connect(function()
	
	local f = script.res.minecraft_death:Clone()
	local n = f.youdied
	f.Parent = player.PlayerGui
	f.TextButton.TextTransparency = 1
	f.TextLabel.Transparency = 1
	f.youdied.TintColor = Color3.fromRGB(255, 255, 255)
	game.TweenService:Create(f.youdied, TweenInfo.new(1), {TintColor = deathcolor}):Play()
	game.TweenService:Create(cam, TweenInfo.new(1), {FieldOfView = 40}):Play()
	f.youdied.Parent = game.Lighting
	game.TweenService:Create(f.TextButton, TweenInfo.new(1), {Transparency = 0}):Play()
	game.TweenService:Create(f.TextLabel, TweenInfo.new(1), {TextTransparency = 0}):Play()
	wait(1)
	f.TextButton.MouseButton1Click:Connect(function()
		f:Destroy()
		n:Destroy()
		game.TweenService:Create(cam, TweenInfo.new(1), {FieldOfView = 70}):Play()

		eventres:WaitForChild("Mm_Died"):Fire(player)
	end)
	
end)

player.CharacterAdded:Connect(function(Character)
	h = Character:FindFirstChildOfClass("Humanoid")
end)

this one is more simple and only updates the variable, it tested this and it should work

ok ill try this out later , tysm

Neither worked. I suggest you to find a way connecting again to the character instance,but IDK how this works…

I think if found the solution, basically angel just checked the humanoid death once but you need to call the death function every single time a new character is added AND when the script first runs

local function onDeath(Character)
	h = Character:FindFirstChildOfClass("Humanoid")

	h.Died:Connect(function()

		local f = script.res.minecraft_death:Clone()
		local n = f.youdied
		f.Parent = player.PlayerGui
		f.TextButton.TextTransparency = 1
		f.TextLabel.Transparency = 1
		f.youdied.TintColor = Color3.fromRGB(255, 255, 255)
		game.TweenService:Create(f.youdied, TweenInfo.new(1), {TintColor = deathcolor}):Play()
		game.TweenService:Create(cam, TweenInfo.new(1), {FieldOfView = 40}):Play()
		f.youdied.Parent = game.Lighting
		game.TweenService:Create(f.TextButton, TweenInfo.new(1), {Transparency = 0}):Play()
		game.TweenService:Create(f.TextLabel, TweenInfo.new(1), {TextTransparency = 0}):Play()
		wait(1)
		f.TextButton.MouseButton1Click:Connect(function()
			f:Destroy()
			n:Destroy()
			game.TweenService:Create(cam, TweenInfo.new(1), {FieldOfView = 70}):Play()

			eventres:WaitForChild("Mm_Died"):Fire(player)
		end)

	end)
	
end

h = Character:FindFirstChildOfClass("Humanoid")

h.Died:Connect(function()
	onDeath(Character, h)
end)

player.CharacterAdded:Connect(function(Character)
	h = Character:FindFirstChildOfClass("Humanoid")
	
	h.Died:Connect(function()
		onDeath(Character, h)
	end)

end)

Also i made the death a function since we call it 2 times to not fill up the script

1 Like

not sure if you fixed this yet or not, but i think i found the reason this didnt work. at the top of your script, you have: game.Players.LocalPlayer.CharacterAdded:Wait() which cancels out the event i provided. simple fix, remove that line and use this code and everything should be working

local h : Humanoid = nil -- variable is nil until the characteradded asigns it

player.CharacterAdded:Connect(function(Character)
	
	h = Character:FindFirstChildOfClass("Humanoid")
	
	h.Died:Once(function() -- Switched to once because the event can only be fired one time
		
		local f = script.res.minecraft_death:Clone()
		local n = f.youdied
		f.Parent = player.PlayerGui
		f.TextButton.TextTransparency = 1
		f.TextLabel.Transparency = 1
		f.youdied.TintColor = Color3.fromRGB(255, 255, 255)
		game.TweenService:Create(f.youdied, TweenInfo.new(1), {TintColor = deathcolor}):Play()
		game.TweenService:Create(cam, TweenInfo.new(1), {FieldOfView = 40}):Play()
		f.youdied.Parent = game.Lighting
		game.TweenService:Create(f.TextButton, TweenInfo.new(1), {Transparency = 0}):Play()
		game.TweenService:Create(f.TextLabel, TweenInfo.new(1), {TextTransparency = 0}):Play()
		wait(1)
		f.TextButton.MouseButton1Click:Connect(function()
			f:Destroy()
			n:Destroy()
			game.TweenService:Create(cam, TweenInfo.new(1), {FieldOfView = 70}):Play()

			eventres:WaitForChild("Mm_Died"):Fire(player)
		end)
		
	end)
	
end)