What function would I use to access a value from another player?
Asked by
6 years ago Edited 6 years ago
I have a button that allows you to challenge a player that you want to play against. Everything works fine, but I want to add a function where if the player you want to battle already has a request from someone else, the RequestRemote wont fire and give the player an error message. I just don't know what function can accomplish this because the Boolean value has to be accessed from the localscript.
The boolean "hasRequest" is created in everyone's Player. This is the value I want to check before sending a request.
Here is my LocalScript for reference:
01 | local id = script.Parent.Parent:WaitForChild( "PlayerID" ) |
02 | local text = script.Parent:WaitForChild( "Battletext" ) |
03 | local Request = game.ReplicatedStorage.DefaultRequest |
04 | local localgui = game:GetService( 'Players' ).LocalPlayer:WaitForChild( "PlayerGui" ) |
05 | local localplayerid = game.Players.LocalPlayer.UserId |
06 | local lookfor = game.ReplicatedStorage.BattleEvent |
07 | local lookForGameNextClick = true |
08 | local player = game:GetService( "Players" ):GetPlayerByUserId(id.Value) |
09 | local localname = game.Players.LocalPlayer.Name |
10 | local iswaiting = game:GetService( 'Players' ).LocalPlayer:WaitForChild( "WaitingForPlayer" ) |
11 | local hasgui = game:GetService( 'Players' ).LocalPlayer:WaitForChild( "hasRequest" ) |
15 | script.Parent.MouseButton 1 Click:connect( function () |
19 | if id.Value = = localplayerid then |
20 | script.Disabled = true |
21 | text.Text = "Can't Do That" |
23 | script.Disabled = false |
27 | if hasgui.Value = = true then |
29 | text.Text = "Waiting!" |
30 | script.Disabled = true |
33 | script.Disabled = false |
36 | if hasgui.Value = = false then |
38 | if iswaiting.Value = = false then |
40 | game.ReplicatedStorage.BoolTrueRemote:FireServer(localname) |
44 | if iswaiting.Value = = true then |
45 | text.Text = "Waiting!" |
46 | script.Disabled = true |
49 | script.Disabled = false |
57 | game.ReplicatedStorage.RequestRemote:FireServer(player) |
ServerScript
01 | local changeRemote = Instance.new( "RemoteEvent" , game.ReplicatedStorage) |
02 | changeRemote.Name = "BoolTrueRemote" |
04 | local change 2 Remote = Instance.new( "RemoteEvent" , game.ReplicatedStorage) |
05 | change 2 Remote.Name = "BoolFalseRemote" |
07 | local declineRemote = Instance.new( "RemoteEvent" , game.ReplicatedStorage) |
08 | declineRemote.Name = "DeclineRemote" |
10 | local Decline = game.ReplicatedStorage.defaultDecline |
12 | local requestRemote = Instance.new( "RemoteEvent" , game.ReplicatedStorage) |
13 | requestRemote.Name = "RequestRemote" |
15 | local Request = game.ReplicatedStorage.DefaultRequest |
17 | local HasGui = Instance.new( "RemoteEvent" ,game.ReplicatedStorage) |
18 | HasGui.Name = "GuiTrueRemote" |
20 | local HasNotGui = Instance.new( "RemoteEvent" ,game.ReplicatedStorage) |
21 | HasGui.Name = "GuiFalseRemote" |
23 | requestRemote.OnServerEvent:Connect( function (plr, plr 2 ) |
24 | local msg = Request:Clone() |
25 | local text = Instance.new( "TextLabel" ) |
26 | local playername = Instance.new( "IntValue" ) |
27 | playername.Value = plr.UserId |
28 | playername.Name = "PlayerID" |
29 | local box = msg:WaitForChild( "MovingBox" ) |
30 | text.Text = plr.Name .. " wants to battle you!" |
31 | text.Size = UDim 2. new( 0.7 , 0 , 1 , 0 ) |
32 | text.Position = UDim 2. new( 0 , 0 , 0 , 0 ) |
33 | text.BackgroundTransparency = 1 |
34 | text.TextScaled = true |
35 | text.TextWrapped = true |
39 | msg.Parent = plr 2 :WaitForChild( "PlayerGui" ) |
41 | playername.Parent = box |
45 | declineRemote.OnServerEvent:Connect( function (plr, plr 2 ) |
46 | local msgs 2 = Decline:Clone() |
49 | msgs 2. Parent = plr 2 :WaitForChild( "PlayerGui" ) |
50 | local boolval = plr 2 :WaitForChild( "WaitingForPlayer" ) |
55 | changeRemote.OnServerEvent:Connect( function (plr) |
57 | local boolvalue = plr:WaitForChild( "WaitingForPlayer" ) |
58 | boolvalue.Value = true |
62 | change 2 Remote.OnServerEvent:Connect( function (plr) |
64 | local boolvalue = plr:WaitForChild( "WaitingForPlayer" ) |
65 | boolvalue.Value = false |
69 | HasGui.OnServerEvent:Connect( function (plr) |
71 | local guiE = plr:WaitForChild( "hasRequest" ) |
76 | HasNotGui.OnServerEvent:Connect( function (plr) |
78 | local guiE 2 = plr:WaitForChild( "hasRequest" ) |
83 | game.Players.PlayerAdded:connect( function (player) |
85 | local bool = Instance.new( "BoolValue" , player) |
87 | bool.Name = "WaitingForPlayer" |
89 | local bool 2 = Instance.new( "BoolValue" , player) |
91 | bool 2. Name = "hasRequest" |