Ending Event not working - Its breaking my game

So the core of my game is basically getting endings, and my whole system just suddenly decided to stop working? I’ve been trying solutions for months and I can’t create anything without endings. It’s literally breaking my game.

Here’s my ‘name checking’ scripts, basically checking the name of the food and giving the proper ending to it. I’ve made them in separate scripts because I thought that you can only give a badge from a regular script and not a local script.
Name checking script 1:

local RP = game:GetService("ReplicatedStorage")
local Events = RP.Events

local prompt = workspace.Cafe.Inside.Plate.Placement.ProximityPrompt

local folder = game.Workspace.Cafe.Inside.Plate.Placement.Items

prompt.Triggered:Connect(function(plr)
	for _,v in pairs(folder:GetChildren()) do
		if v:IsA("Part") then
			print("There is something inside of the folder! Checking the name;"..v.name.Value)
				if v.name.Value == "Muffin" then
				
					script.Parent.EndingName.Text = "Muffin"
					script.Parent.Desc.Text = "It was stale due to being left out for too long. Gross!"
				
				elseif v.name.Value == "Donuts" then
				
					script.Parent.EndingName.Text = "Donuts"
					script.Parent.Desc.Text =  "How are you gonna finish them all?"		
				
			end
		end
	end
end)

this local script checks the name of the object and changes the text based off of it, it is parented to a frame inside of startergui.

Name checking script 2:

local RP = game:GetService("ReplicatedStorage")
local Events = RP.Events

local prompt = workspace.Cafe.Inside.Plate.Placement.ProximityPrompt

local folder = game.Workspace.Cafe.Inside.Plate.Placement.Items

prompt.Triggered:Connect(function(plr)
	for _,v in pairs(folder:GetChildren()) do
		if v:IsA("Part") then
			print("There is something inside of the folder! Checking the name;"..v.name.Value)
				if v.name.Value == "Muffin" then
				
					Events.GiveEnding:FireClient(plr, "Classic.", 2147132836)
				
				elseif v.name.Value == "Donuts" then
				
 					Events.GiveEnding:FireClient(plr,"mm", 2147434744)
			end
		end
	end
end)

this is a regular script still parented to a frame inside starter gui. I have moved it to serverscriptservice it still doesnt work. it’s supposed to give you a badge based off of the ending you get.

This is another ending handler inside of the same frame inside of starter gui:

local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage.Events
local sound = game.Workspace.Music["splat.wav"]

Events:FindFirstChild("GiveEnding").OnClientEvent:Connect(function()
	script.Parent.Visible = true
	local newpos = UDim2.new(-0.001, 0, -0, 0)
	local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out)
	
	local tween = TweenService:Create(script.Parent, tweenInfo, {Position = newpos})

	tween:Play()
	wait(2)
	script.Parent["Ending:"].Visible = true
	sound:Play()
	wait(2)
	script.Parent.EndingName.Visible = true
	sound:Play()
	wait(3)
	sound:Play()
	script.Parent.Desc.Visible = true
end)

its a local script and it basically functions so that when you put a food on the plate, it shows the ending screen. this hasnt been working at all, it hasnt been even showing up. ive tried making it a local script and changing the event, and a regular script and changing the event. it still doesnt work.

idk why you would need this, but just in case here is the script for when you place food on the plate overall.

local RP = game:GetService("ReplicatedStorage")
local Events = RP.Events
local prompt = workspace.Cafe.Inside.Plate.Placement.ProximityPrompt

script.Parent.ChildAdded:Connect(function(item)
	prompt.Triggered:Connect(function(plr)
		local inv = plr:FindFirstChild("Inventory")
		for _,v in pairs(inv:GetChildren()) do
			if v:IsA("Part") then
				print("Player has an item! Detecting if it's purchased or not...")
				if v.Purchased.Value == false then
					print("You need to purchase the item first!")
				else
					print("Player has purchased item! Giving ending..")
						v.Parent = workspace.Cafe.Inside.Plate.Placement.Items
						v.Position = workspace.Cafe.Inside.Plate.Placement.TP.Position
						v:FindFirstChild("Attachment").ProximityPrompt:Destroy()
						prompt.Enabled = false
					
					plr.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.Cafe.Inside.SpawnTp.Position)
						plr.Character:FindFirstChild("Humanoid").WalkSpeed = 0
						plr.Character:FindFirstChild("Humanoid").Sit = true
						plr.Character.HumanoidRootPart.Anchored = true
					
					item:Destroy()
					Events.PlacementEvent:FireServer()
					wait(2)
					end
				end
			end
	end)
end)

theres a few other scripts if you need them but these im basically having the most trouble with. thank you for reading and im sorry its so long, last post i did that was long like this i couldnt get any help :sob:
seriously though i dont know the issue and ive tried a billion things. if you need more scripts and stuff i will gladly oblige

3 Likes

you server script never awards the badge. it just fires to the client with some id and string

the client cannot award badges you can only award badges on the server with BadgeService:AwardBadge(userId, badgeId)

4 Likes

this is the script that did this

local badgeservice = game:GetService("BadgeService")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage.Events

local prompt = workspace.Cafe.Inside.Plate.Placement.ProximityPrompt

prompt.Triggered:Connect(function(plr)
	Events:FindFirstChild("GiveEnding").OnServerEvent:Connect(function(plr, message, badgeId)
		badgeservice:AwardBadge(plr.UserId, badgeId)
		wait(5)
		plr:Kick(message)
	end)
end)

edit: i accidentally edited this message LOL ignore that

few issues with this
you are connecting this event every time somebody joins. you should only connect it once otherwise it will call it more than once

also you never fire to the server (in any of the scripts you shown) only to the client. so again this never runs

1 Like

i get that, but i dont really know how to write/rewrite these scripts to fix that. can you please help?

well you dont need to connect to the ending event remote on the server at all since when you are firing to the client, you already know they got the ending

so just move the code to award the badge over to where you fire the event GiveEnding to the client

1 Like

i needed a break yesterday but im rewriting the code now lol tysm for your help!!!

1 Like

okay so i tried my best to do that and yet it still doesnt work?

local TweenService = game:GetService("TweenService")
local badgeservice = game:GetService("BadgeService")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage.Events

local prompt = workspace.Cafe.Inside.Plate.Placement.ProximityPrompt
local folder = game.Workspace.Cafe.Inside.Plate.Placement.Items
local sound = game.Workspace.Music["splat.wav"]

function Award(plr, badgeId, message)
	badgeservice:AwardBadge(plr.UserId, badgeId)
	wait(5)
	plr:Kick(message)
end

prompt.Triggered:Connect(function(plr)
	script.Parent.Visible = true
	local newpos = UDim2.new(-0.001, 0, -0, 0)
	local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out)
	
	local tween = TweenService:Create(script.Parent, tweenInfo, {Position = newpos})

	tween:Play()
	wait(2)
	script.Parent["Ending:"].Visible = true
	sound:Play()
	wait(2)
	script.Parent.EndingName.Visible = true
	sound:Play()
	wait(3)
	sound:Play()
	script.Parent.Desc.Visible = true
	
	for _,v in pairs(folder:GetChildren()) do
		if v:IsA("Part") then
			print("There is something inside of the folder!")
			if v.name.Value == "Muffin" then

				Award(plr, 2147132836, "Classic.")

			elseif v.name.Value == "Donuts" then

				Award(plr, 2147434744, "mm")
			end
		end
	end
end)

ill try to kind of explain this whole script.
so first i establish the function that awards the badge, instead of using an event. then, when the prompt gets triggered, it obviously makes the frame visible, tweens it, then makes the ending name and description and stuff visible. then, after that, it checks inside of a part to check whether or not its a muffin, or donut. then, it awards the badge based off of whichever you get.

sorry to keep bothering you, but this is basically how i understood what you said. would something like this work? or how would i tweak it?

you cant award badges on the client
you must award badges on the server

1 Like

its a server script. am i not awarding on the server?

edit: also for some reason at the “print(“There is something inside of the folder! Checking the name;”…v.name.Value)” it prints twice? i dont know if this has anything to do with the other script, cause this is a seperate local script, but idk lolll

local RP = game:GetService("ReplicatedStorage")
local Events = RP.Events

local prompt = workspace.Cafe.Inside.Plate.Placement.ProximityPrompt

local folder = game.Workspace.Cafe.Inside.Plate.Placement.Items

prompt.Triggered:Connect(function(plr)
	for _,v in pairs(folder:GetChildren()) do
		if v:IsA("Part") then
			print("There is something inside of the folder! Checking the name;"..v.name.Value)
				if v.name.Value == "Muffin" then
				
					script.Parent.EndingName.Text = "Muffin"
					script.Parent.Desc.Text = "It was stale due to being left out for too long. Gross!"
				
				elseif v.name.Value == "Donuts" then
				
					script.Parent.EndingName.Text = "Donuts"
					script.Parent.Desc.Text =  "How are you gonna finish them all?"		
				
			end
		end
	end
end)

the script you showed me i assume was a local script because you were editing gui elements

it prints twice because you are looping through a folder and checking if theres parts in it

can i see where these scripts are parented

1 Like

image

thats parented to startergui.

whats in the folder you loop through in the server script

1 Like

there is nothing until you put something in there

image

  • thats parented to workspace btw

then when i place somthing in there
image

if you need the placement script lmk

does the server print if theres anything in the folder?

if not then those parts only exist on the client so the server doesnt know they exist. you have to create them on the server if you want the server to know anything is in there

1 Like

good point. it does only print on the client.
but how would what would i change inside of the placement script? its a local script under
image
i cant really access the inventory if its on the server side so im really questioning making another script or something??? i really dont know what to do lol

Try to change FindFirstChild to WaitForChild while finding event in third script.
Like this:

local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage.Events
local sound = game.Workspace.Music["splat.wav"]

Events:WaitForChild("GiveEnding").OnClientEvent:Connect(function()
	script.Parent.Visible = true
	local newpos = UDim2.new(-0.001, 0, -0, 0)
	local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out)
	
	local tween = TweenService:Create(script.Parent, tweenInfo, {Position = newpos})

	tween:Play()
	wait(2)
	script.Parent["Ending:"].Visible = true
	sound:Play()
	wait(2)
	script.Parent.EndingName.Visible = true
	sound:Play()
	wait(3)
	sound:Play()
	script.Parent.Desc.Visible = true
end)
1 Like

you are gonna have to rewrite all the code to use the client and server
you should always have the server handling inventories while the client just requests the data and cannot change anything. this prevents exploiters and allows the game to run smoother since the server knows everybody’s inventory

1 Like

i didnt think it really mattered cuz its a 1 player game haha

you should always still have the server handle anything to do with inventories and the client only to deal with guis and displaying it to the player

1 Like