SendNotification to one player

Hey there, I am attempting to create a notification that sends to a certain player when an action is completed - in this case whether the player accepts or denies the give request. I am unsure on how to send a notification to the Barista and the Barista only.

Server script:

HandToEvent.OnServerEvent:Connect(function(Barista, val)
	if val == true then
		print("Accepted")
		TargetTool.Parent = Target.Backpack
		Accepted:FireClient(Barista)
	elseif val == false then
		Denied:FireClient(Barista)
		print("Declined")
	    return
    end
end)

Local Script:

Accepted.OnClientEvent:Connect(function()
	game:GetService("StarterGui"):SetCore("SendNotification", {
		Title = "Tasté Utility",
		Text = "Your customer accepted the give request!"
	})
end)

Denied.OnClientEvent:Connect(function()
	game:GetService("StarterGui"):SetCore("SendNotification", {
		Title = "Tasté Utility",
		Text = "Your customer didn't accept the give request!"
	})
end)

For the local script do this:

local StarterGui = game:GetService("StarterGui")

local function FireNotificationFunction(IsVal)
   --Add this if you want
   --assert(typeof(IsVal) == "boolean", "Value is not a boolean")

   if IsVal then --If IsVal is true then accept it but if not then don't accept it
      StarterGui:SetCore("SendNotification", {
		   Title = "Tasté Utility",
		   Text = "Your customer accepted the give request!"
	   })
   else
      StarterGui:SetCore("SendNotification", {
		  Title = "Tasté Utility",
		  Text = "Your customer didn't accept the give request!"
	  })
   end
end

InsertEventName.OnClientEvent:Connect(FireNotificationFunction)

Sorry if it doesn’t work, I did not do this script in Roblox Studio.

Yeah, this didn’t work.

esfdsad

Change the server script to this:

HandToEvent.OnServerEvent:Connect(function(Barista, val)
	InsertEventName:FireClient(Barista, val)
end)

And the local script to this:

local StarterGui = game:GetService("StarterGui")

local function FireNotificationFunction(Player, IsVal)
   --Add this if you want
   --assert(typeof(IsVal) == "boolean", "Value is not a boolean")

   if IsVal then --If IsVal is true then accept it but if not then don't accept it
      StarterGui:SetCore("SendNotification", {
		   Title = "Tasté Utility",
		   Text = "Your customer accepted the give request!"
	   })
   else
      StarterGui:SetCore("SendNotification", {
		  Title = "Tasté Utility",
		  Text = "Your customer didn't accept the give request!"
	  })
   end
end

InsertEventName.OnClientEvent:Connect(FireNotificationFunction)

I am now receiving the error: Unable to cast value to Object on the lines where the event is being fired.

Did you replace InsertEventName? And change the HandToEvent to a BindableEvent event in explorer.

Completely forgot about the event part, I will change that now and get back to you.

This time, I have no errors but this did not work. Would you like a place file to have a look? I’m really not sure what the issue is.

Sure! This will help me a lot to help you and give me the information needed to help you.

123.rbxl (49.4 KB)

This version works 100% fine but you need to uncomment a lot of things for your game and change some things.
Server script:

--// script created by: @datastoress

--// handler is located in the gui!!!!

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--local Configuration = require(game:GetService("ServerScriptService").Configuration)
local GroupID = 1
local MinRank = 254

local HandToGUI = script:WaitForChild("HandToGUI")
local HandToEvent = ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("HandToEvent")

--local Accepted = ReplicatedStorage.RemoteEvents.Accepted
--local Denied = ReplicatedStorage.RemoteEvents.Denied

local Decision = ReplicatedStorage.RemoteEvents.Decision


HandToEvent.Event:Connect(function(Barista, val)
	Decision:FireClient(Barista, val)
end)

Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		Message = Message:lower()
		
		--if Player:GetRankInGroup(GroupID) >= MinRank then
			local args = Message:split(" ")
			
			if args[1] == ":handto" then
				
				local function GetPlayerFromPartial(Input)
					for _, Player in ipairs(Players:GetPlayers()) do
						if (string.lower(Input) == string.sub(string.lower(Player.Name), 1, #Input)) then
							return Player
						end
					end
				end
				
				local Target = {
					Name = "Timmy1234"
				}
				local Barista = Player
				print(Target.Name..": Target")
				print(Barista.Name..": Barista")
				
				if Target then
					if Target.Name == Barista then
						warn("Tasté Utility System | You cannot give items to yourself!")
					else
						local TargetTool = Barista.Character:FindFirstChildOfClass("Tool")
						print(true)
						
						if TargetTool then
							local NewGUI = HandToGUI:Clone()
							local Info = NewGUI:WaitForChild("MainFrame"):WaitForChild("Info")
							Info.Text = Barista.Name.." is attempting to give you "..TargetTool.Name..". If this is your barista, click accept, otherwise, click deny!"
							NewGUI.Parent = Barista.PlayerGui
							NewGUI:WaitForChild("MainFrame"):TweenPosition(UDim2.new(0.5, -210, 0.5, -70), "In", "Sine", 0.3)
							Decision:FireClient(Barista, val)
							print(true)
						end
					end
				end
				
			end
		--end
		
	end)
end)

Local script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Accept = script.Parent:WaitForChild("MainFrame"):WaitForChild("Confirm")
local Decline = script.Parent:WaitForChild("MainFrame"):WaitForChild("Cancel")
local GUI = script.Parent

local HandToEvent = ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("HandToEvent")
--local Accepted = ReplicatedStorage.RemoteEvents.Accepted
--local Denied = ReplicatedStorage.RemoteEvents.Denied

local Decision = ReplicatedStorage.RemoteEvents.Decision

Accept.Activated:Connect(function()
	HandToEvent:Fire(true)
	GUI:Destroy()
	game:GetService("StarterGui"):SetCore("SendNotification", {
		Title = "Tasté Utility",
		Text = "You accepted the give request!"
	})
end)

Decline.Activated:Connect(function()
	HandToEvent:Fire(false)
	GUI:Destroy()
	game:GetService("StarterGui"):SetCore("SendNotification", {
		Title = "Tasté Utility",
		Text = "You didn't accept the give request!"
	})
end)

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

local StarterGui = game:GetService("StarterGui")

local function FireNotificationFunction(IsVal)
	--Add this if you want
	--assert(typeof(IsVal) == "boolean", "Value is not a boolean")

	if IsVal then --If IsVal is true then accept it but if not then don't accept it
		StarterGui:SetCore("SendNotification", {
			Title = "Tasté Utility",
			Text = "Your customer accepted the give request!"
		})
	else
		StarterGui:SetCore("SendNotification", {
			Title = "Tasté Utility",
			Text = "Your customer didn't accept the give request!"
		})
	end
end

Decision.OnClientEvent:Connect(FireNotificationFunction)

Could I just ask why I am getting an unknown global variable for val?

I forgot to replace val with true, as I said please change things to your fitting before you add this to your game,

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.