I’m trying to make an invite to a duel system. And I want to make it so targetPlayer
can see if they’re being invited and have a choice to agree on it.
acceptButton.MouseButton1Click:Connect(function() --invite someone
infoText.Text = ""
popDown(popUp)
----------|SEND CHALLENGE TO DUEL|----------
print("asd")
if game.Players:GetPlayerFromCharacter(target) == nil then return end --for testing purposes
local targetPlayer = game.Players:GetPlayerFromCharacter(target) --target is a character
local targetGui = targetPlayer:WaitForChild("PlayerGui")
local screenGui = targetGui:WaitForChild("ScreenGui")
local hoverGui = screenGui.Hover
local hoverButton = hoverGui.HoverButton
local popUp = screenGui.PopUp
local infoText = popUp.Info
local acceptButton = popUp.AcceptButton
local rejectButton = popUp.RejectButton
infoText.Text = "You are being invited to a duel by"..player.Name.."."
--so on, so forth...
----------|SEND CHALLENGE TO DUEL|----------
wait(5)
poppedUp = false
end)
Am I on the right track?
1 Like
I think what you should do is make string values that are accessed from both clients via using remote events.
1 Like
Thanks! I’ll definitely try it.
Alright, forgot to add, make :GetPropertyChangedSignal
to run the event on both clients.
1 Like
What, is it not popping up on the players you want it to pop up on?
1 Like
Try this script.
acceptButton.MouseButton1Click:Connect(function() --invite someone
infoText.Text = ""
popDown(popUp)
----------|SEND CHALLENGE TO DUEL|----------
print("asd")
if game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui') == nil then return end --for testing purposes
local targetPlayer = game.Players:GetPlayerFromCharacter(target) --target is a character
local targetGui = targetPlayer:WaitForChild("PlayerGui")
local screenGui = targetGui:WaitForChild("ScreenGui")
local hoverGui = screenGui.Hover
local hoverButton = hoverGui.HoverButton
local popUp = screenGui.PopUp
local infoText = popUp.Info
local acceptButton = popUp.AcceptButton
local rejectButton = popUp.RejectButton
infoText.Text = "You are being invited to a duel by"..player.Name.."."
--so on, so forth...
----------|SEND CHALLENGE TO DUEL|----------
wait(5)
poppedUp = false
end)
Wait, do you mean I was doing it right even without the use of RemoteEvents??
You have to use RemoteEvents for that. You can’t change someone else’s GUI from a local script, only your own.
I wouldn’t go for string values and .Chaged/:GetPropertyChanged signal to achieve that communication.
You should fire an event to the server (with the specified/invited player object), then fire the remote event to the invited player to show up the GUI.
You basically use the server as a bridge between the 2 clients.
Code example:
--Client 1 (local script)
local targetPlayer --get the player here somehow
local remoteEvent = nil --Path to your remote event.
remoteEvent:FireServer(targetPlayer) --Tell the server to inform the other player
--Server code:
local remoteEvent = nil --Path to remote event.
remoteEvent.OnServerEvent:Connect(function(sender, invited) --When the event is fired
remoteEvent:FireClient(invited, sender) --Fire to the person that you invited, with the sender player.
end)
--Client 2 (local script)
--Note: You can use the same local script for this, you don't have to use different ones.
local remoteEvent = nil --Path to remote event
local plr = game:GetServer("Players").LocalPlayer --Get the current client'
local PlayerGui = plr:WaitForChild("PlayerGui")
remoteEvent.OnClientEvent:Connect(function(sender) --When you recieve an invite, do:
--Change the GUI using the PlayerGui:
local screenGui = PlayerGui :WaitForChild("ScreenGui")
local hoverGui = screenGui.Hover
local hoverButton = hoverGui.HoverButton
local popUp = screenGui.PopUp
local infoText = popUp.Info
local acceptButton = popUp.AcceptButton
local rejectButton = popUp.RejectButton
infoText.Text = "You are being invited to a duel by".. sender.Name .."."
end)
1 Like
This is like my entire script for what I’m trying implement…
Client:
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local battleRequestEvent = game.ReplicatedStorage.BattleRequest
local screenGui = script.Parent
local hoverGui = screenGui.Hover
local hoverButton = hoverGui.HoverButton
local popUp = screenGui.PopUp
local infoText = popUp.Info
local acceptButton = popUp.AcceptButton
local rejectButton = popUp.RejectButton
local poppedUp = false
local function popUpTween(gui)
gui:TweenSize(UDim2.new(0.5,0,0.5,0), Enum.EasingDirection.Out, Enum.EasingStyle.Elastic, 0.5)
end
local function popDownTween(gui)
gui:TweenSize(UDim2.new(0,0,0,0), Enum.EasingDirection.Out, Enum.EasingStyle.Elastic, 0.5)
end
-----------------------------------------|FOR PC PLAYERS|-----------------------------------------
mouse.Move:Connect(function()
local target = mouse.Target
if target and target.Parent then
if target.Parent:FindFirstChild("Humanoid") and not poppedUp then
hoverGui.Visible = true
hoverGui.Position = UDim2.new(0,mouse.X + 10,0,mouse.Y + 5)
else
hoverGui.Visible = false
end
end
end)
UIS.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.E then
local character = mouse.Target
if character and character.Parent then
if character.Parent:FindFirstChild("Humanoid") and not poppedUp then
poppedUp = true
hoverGui.Visible = false
popUp.Visible = true
popUp:Tween(popUp)
infoText.Text = "Would you like to send request to battle against "..character.Parent.Name.."?"
end
end
end
end)
acceptButton.MouseButton1Click:Connect(function()
infoText.Text = ""
popDownTween(popUp)
battleRequestEvent:FireServer()
wait(5)
poppedUp = false
end)
rejectButton.MouseButton1Click:Connect(function()
infoText.Text = ""
popDownTween(popUp)
wait(5)
poppedUp = false
end)
-----------------------------------------|FOR PC PLAYERS|-----------------------------------------
-----------------------------------------|FOR MOBILE PLAYERS|-----------------------------------------
--to be done yet
-----------------------------------------|FOR MOBILE PLAYERS|-----------------------------------------
battleRequestEvent.OnClientEvent:Connect(function(targetPlayer)
local targetPlayerGui = targetPlayer:FindFirstChild("PlayerGui")
local TPGPopUp = targetPlayerGui:FindFirstChild("PopUp")
local TPGInfoText = TPGPopUp:FindFirstChild("Info")
local TPGAcceptButton = TPGPopUp:FindFirstChild("AcceptButton")
local TPGRejectButton = TPGPopUp:FindFirstChild("RejectButton")
popUpTween(TPGPopUp)
TPGInfoText.Text = player.."has send request to battle against you!"
TPGAcceptButton.MouseButton1Click:Connect(function()
infoText.Text = ""
popDownTween(TPGPopUp)
----------|DUEL|----------
--to be done yet
----------|DUEL|----------
end)
TPGRejectButton.MouseButton1Click:Connect(function()
infoText.Text = ""
popDownTween(TPGPopUp)
end)
end)
Server:
local battleRequestServer = game.ReplicatedStorage.BattleRequest
battleRequestServer.BattleRequest.OnServerEvent:Connect(function(player)
battleRequestServer:FireClient(player)
end)
Really sorry for the long script but am I doing the right thing, sir?
Not exactly, but you are in the right direction.
For example, you should fire the event when you send the invite, not when you accept it, and in the () of the :FireServer you should put the player you want to invite.
In the server, after the player add invited argument and fire it instead.
Server code:
local battleRequestServer = game:GetService("ReplicatedStorage").BattleRequest
local remoteEvent = battleRequestServer:WaitForChild("BattleRequest")
remoteEvent.OnServerEvent:Connect(function(player, invited)
remoteEvent:FireClient(invited, player)
end)
1 Like