Accept-Button not working

Hi! So I’m scripting an Accept-Item button for my Cafe but for some reason it doesn’t work.
When the player clicks Yes or No, it tweens away but it doesn’t give him/her the item.
It also doesn’t print yes.
Code:
Server Script

local item = getItem(player.Character)
			--Check if the player wanted it or not
				local checkIfPlayerWantedIt = game.ReplicatedStorage.Remotes.CheckIfPlayerWantedItem
				if player.Name:lower() ~= v.Name:lower() then
					local invoke = checkIfPlayerWantedIt:InvokeClient(v)
					repeat wait(1) until invoke == "Give" or invoke == false
					if invoke == "Give"  then
						print("Yes")
						local clone = item:Clone()
						item:Destroy()
						clone.Parent = v.Character
						player.leaderstats.Points.Value = player.leaderstats.Points.Value +1
					end
				end

Local Script:

local replicatedStorage = game:GetService("ReplicatedStorage")
local tweenService = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local char = workspace:WaitForChild(player.Name) or workspace[player.Name]
local playerGui = player:WaitForChild("PlayerGui")
local didOrderFrame = playerGui.didOrder.didOrderFrame
local checkIfPlayerWantedIt = game.ReplicatedStorage.Remotes.CheckIfPlayerWantedItem
local yesButton = didOrderFrame.YesButton
local noButton = didOrderFrame.NoButton

--Can't see: {0.346, 0},{-0.3, 0}
--Can see: {0.346, 0},{0.4, 0}

checkIfPlayerWantedIt.OnClientInvoke = function()
	--Tween it
	didOrderFrame:TweenPosition(UDim2.new(0.346, 0,0.4, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.4)
	yesButton.MouseButton1Down:Connect(function()
		didOrderFrame:TweenPosition(UDim2.new(0.346, 0,-0.4, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.4)
			return "Give"
	end)
	noButton.MouseButton1Down:Connect(function()
			didOrderFrame:TweenPosition(UDim2.new(0.346, 0,-0.4, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.4)
			return false
	end)
end

Thank you!

If you want the full script, tell me, but I don’t think it’s necessary.

What I like to do is add a print after a certain function / if statement and change it’s position every time I finish Running the Intended Script to see which part is working or not

2 Likes

Local Script:

	didOrderFrame:TweenPosition(UDim2.new(0.346, 0,0.4, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.4)
	yesButton.MouseButton1Down:Connect(function()
		didOrderFrame:TweenPosition(UDim2.new(0.346, 0,-0.4, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.4)
		print("YesClientYes") --gets printed
			return "Give"
	end)

Server Script:

local invoke = checkIfPlayerWantedIt:InvokeClient(v)
					print(invoke) --nil
					repeat wait(1) until invoke == "Give" or invoke == false
					if invoke == "Give"  then
						print("Yes")
						local clone = item:Clone()
						item:Destroy()	
						clone.Parent = v.Character
						player.leaderstats.Points.Value = player.leaderstats.Points.Value +1

It prints no the whole time.

repeat wait() print("no") until invoke == "Give" or invoke == "NotGive"

Local Script:

checkIfPlayerWantedIt.OnClientInvoke = function()
	--Tween it
	didOrderFrame:TweenPosition(UDim2.new(0.346, 0,0.4, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.4)
	yesButton.MouseButton1Down:Connect(function()
		didOrderFrame:TweenPosition(UDim2.new(0.346, 0,-0.4, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.4)
		print("YesClientYes")
			return "Give"
	end)
	noButton.MouseButton1Down:Connect(function()
		didOrderFrame:TweenPosition(UDim2.new(0.346, 0,-0.4, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.4)
		print("YesClientNo")
			return "NotGive"
	end)
end

I think I know why. It’s setting the value of invoke to nil when the button didn’t get clicked yet.

How could I avoid that without invoking it the whole time?
(repeat wait() print("no") until checkIfPlayerWantedIt:InvokeClient(v) == "Give" or checkIfPlayerWantedIt:InvokeClient(v) == "NotGive")

You could add a debounce value to check if it has been pressed. that way it wont just automatically do it all the time

1 Like