I have a ServerScript (below) that is meant to generate character values and change character appearance, and then fire a RemoteEvent in replicated storage sending the Data to the client of the Player who clicked the button.
DataScript = require(game.ReplicatedStorage.Modules.CharacterData)
CharacterTemplate = game.ReplicatedStorage.ReplicatedAssets.Char
script.Parent.ClickDetector.MouseClick:Connect(function(Player)
local Pos = Player.Character.HumanoidRootPart.CFrame
Player.Character = nil
Player = game.Players:FindFirstChild(Player.Name)
local function ClearModel()
Player.Character = CharacterTemplate:Clone()
Player.Character.HumanoidRootPart.CFrame = Pos
Player.Character.Parent = game.Workspace
end
ClearModel()
local Data = DataScript.GenerateCharacter()
local SkinColor = Data.Appearance.SkinColor:Clone()
SkinColor.Parent = Player.Character
print(Data)
for i, v in Data.Appearance.Hair do
local Hair = v:Clone()
Hair.Parent = Player.Character
if Hair.Handle:FindFirstChild("Mesh") then
Hair.Handle.Mesh.TextureId = Data.Appearance.HairColor.Texture
elseif Hair.Handle:FindFirstChild("SpecialMesh") then
Hair.Handle.SpecialMesh.TextureId = Data.Appearance.HairColor.Texture
end
end
game.ReplicatedStorage.StatScreenEvent:FireClient(Player, Data)
end)
The issue is that it doesn’t seem to be firing at all, I’ve tried changing it to my username specifically, or using FireAllClients and my LocalScript (below) located in the StarterGUI does not respond. I tested it in another script that simply fires the event to all clients after 4 seconds have passed and it seems to at the very least fire (albiet causing an error due to lack of data parameters), but I can’t seem to figure out why it’s not working in the script above. Any help would be greatly appreciated.
local StatScreenEvent = game.ReplicatedStorage.StatScreenEvent
StatScreenEvent.OnClientEvent:Connect(function(Data)
print("hello")
script.Parent["Rarity: "].Text = "Rarity: "..Data.Rarity
script.Parent["Race: "].Text = "Race: "..Data.Race.Name
script.Parent["Weapon:"].Text = "Weapon: "..Data.Weapon
for i, v in Data.Traits do
local TraitLabel = Instance.new("TextLabel")
TraitLabel.Text = v.Name
TraitLabel.Size = UDim2.new(1, 0, 0, 100)
TraitLabel.Parent = script.Parent.ScrollingFrame
end
end)
And you’re saying the connection to OnClientEvent doesn’t work (nothing printing to output)? I could easily be wrong, but it might be that the client connection isn’t made before the server fires the event.
I’m just extremely confused since you initially said that it didn’t fire, but then at some point it started working.
the serverscript is working perfectly fine, it’s the localscript that isn’t running at all. If I put the print statement before StatScreenEvent:FireClient(), it would simply print the player who pushed the button serverside. If I were to instead place the print statement in the localscript (in the function that is), it would not print anything at all.
I modified the code try this:
local DataScript = require(game.ReplicatedStorage.Modules.CharacterData)
local CharacterTemplate = game.ReplicatedStorage.ReplicatedAssets.Char
local function ClearModel(Player, Pos)
local NewCharacter = CharacterTemplate:Clone()
NewCharacter.HumanoidRootPart.CFrame = Pos
NewCharacter.Parent = game.Workspace
Player.Character = NewCharacter
end
script.Parent.ClickDetector.MouseClick:Connect(function(Player)
local Pos = Player.Character.HumanoidRootPart.CFrame
Player.Character = nil
Player = game.Players:FindFirstChild(Player.Name)
ClearModel(Player, Pos)
local Data = DataScript.GenerateCharacter()
local SkinColor = Data.Appearance.SkinColor:Clone()
SkinColor.Parent = Player.Character
for i, v in ipairs(Data.Appearance.Hair) do
local Hair = v:Clone()
Hair.Parent = Player.Character
local Mesh = Hair.Handle:FindFirstChildWhichIsA("Mesh") or Hair.Handle:FindFirstChildWhichIsA("SpecialMesh")
if Mesh then
Mesh.TextureId = Data.Appearance.HairColor.Texture
end
end
game.ReplicatedStorage.StatScreenEvent:FireClient(Player, Data)
Let me simplify it, since there’s no reason for me to have written my full serverscript here
This down below does not fire the local script that I wrote in my original post.
Like for example, this script fires my client just fine. It has to be a problem with the clickdetector interaction, because even firing all clients on my original script does not work.
local CharData = require(game.ReplicatedStorage.Modules.CharacterData)
wait(4)
game.ReplicatedStorage.StatScreenEvent:FireClient(game.Players.LuxSaar, CharData.GenerateCharacter())
I found the problem, It was that my character was resetting and then it didn’t have time to load the GUI, I fixed it by adding a wait() between the ClearModel() function and the rest of the script