Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

RemoteEvents affecting player B's values when player A enters them?

Asked by
Hypgnosis 186
5 years ago
Edited 5 years ago

Okay, so I have a overhead Gui. Everything is working great, except for one thing. I'll give the problem scenario:

Player A joins and can edit the Gui Text and Visible values with a TextBox and TextButton.

Player B joins, and can do the same. However, when Player A tries to edit their values after Player B joins, they edit Player B's values instead of their own.

Server Script:

local repStorage = game:GetService('ReplicatedStorage')
local remoteOne = repStorage:FindFirstChild('Remote')
local remoteTwo = repStorage:FindFirstChild('RemoteTwo')

local iFolder = script:WaitForChild('Items')
local compile = iFolder:WaitForChild('Compile')
require(compile)
local compiled = iFolder:WaitForChild('Overhead')

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        if Character:FindFirstChild('Humanoid') and Character:FindFirstChild('Head') then
            local Hum = Character:WaitForChild('Humanoid')
            local Head = Character:WaitForChild('Head')
            Hum.DisplayDistanceType = ('None')
            comClone = compiled:Clone()
            comClone.Parent = Head
            comClone.Data.Text = Player.Name
        end
    end)
end)

-- This remote event cooresponds to the custom name script.
remoteTwo.OnServerEvent:Connect(function(Player, enterName)
    comClone.Data.Text = enterName
end)


-- The remote event cooresponds to the name toggle.
remoteOne.OnServerEvent:Connect(function(Player)
    if comClone.Data.Visible == true then
        comClone.Data.Visible = false
    else
        comClone.Data.Visible = true
    end
end)

Local Script:

local repStorage = game:GetService('ReplicatedStorage')
local Players = game:GetService('Players')
local uis = game:GetService('UserInputService')
local remoteOne = repStorage:FindFirstChild('Remote')
local remoteTwo = repStorage:FindFirstChild('RemoteTwo')
local playerGui = Players.LocalPlayer:FindFirstChild('PlayerGui'):FindFirstChild('screenGui')


-- The gui toggle function.
playerGui.toggleGUI.MouseButton1Click:Connect(function()
    if playerGui.main.Visible == false then
        playerGui.main.Visible = true
    else
        playerGui.main.Visible = false
    end
end)


-- The name toggle function. Changes Data.Visible to true.
playerGui.main.toggleName.MouseButton1Click:Connect(function()
    remoteOne:FireServer()
end)


-- The enter name function. It connects to the overheadName server script.
playerGui.main.enterName.FocusLost:Connect(function(enterPressed)
    if enterPressed then
        remoteTwo:FireServer(playerGui.main.enterName.Text)
    end
end)
0
Is comClone created somewhere else - or is it acting as some sort of global variable from within your CharacterAdded function? (server script). Seems like relevant information as well as where the issue lies. SummerEquinox 643 — 5y
0
comClone is created from that CharacterAdded function and does act as a global variable for the rest of the server script. It clones the Overhead Data which is stored in a module script within the folder called 'Items'. Hypgnosis 186 — 5y

Answer this question