I’m trying to make a Gui appear depending on whether the players won or not, but nothing happens??
For some reason the Win and Lose events don’t work? I’m pretty sure they fire because there are no errors whatsoever, the localscripts just don’t work??
here’s the relevant chunk of the ServerScript:
game.ReplicatedStorage.Events.Start.Event:Connect(function(startgame)
--respawn & reward players--
for index, plr in pairs(players:GetPlayers()) do -- Gets all the players
plr:LoadCharacter() -- Respawns them
plr.Character:WaitForChild("HumanoidRootPart") -- Waiting for character to exist
plr:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
local points = plr:WaitForChild("leaderstats"):WaitForChild("Points")
if FI.Value < 10 then
game.ReplicatedStorage.Events.Win:FireAllClients()
points.Value = points.Value + reward.Value * 10
print("Winners")
else
game.ReplicatedStorage.Events.Lose:FireAllClients()
print("Losers")
end
end
LocalScripts:
local Info = TweenInfo.new(1)
local Tween = game:GetService("TweenService"):Create(script.Parent,Info,{TextTransparency=0})
local Tween2 = game:GetService("TweenService"):Create(script.Parent,Info,{TextTransparency=1})
game.ReplicatedStorage.Events.Lose.OnClientEvent:Connect(function()
script.Parent.Lose:Play()
Tween:Play()
wait(4.5)
Tween2:Play()
end)
local Info = TweenInfo.new(1)
local Tween = game:GetService("TweenService"):Create(script.Parent,Info,{TextTransparency=0})
local Tween2 = game:GetService("TweenService"):Create(script.Parent,Info,{TextTransparency=1})
game.ReplicatedStorage.Events.Win.OnClientEvent:Connect(function()
script.Parent.Cheer:Play()
Tween:Play()
wait(4.5)
Tween2:Play()
end)
I’ve never been stumped on something seemingly so simple, I’ve tried just about everything I could think of the past few days.
Any and all help is appreciated, thanks in advance
Alright so, whats wrong here is, the code runs one time when the round starts. For you to know when the “FI” value changes, you would have to do something like this:
FI:GetPropertyChangedSignal("Value"):Connect(function()
if FI.Value <10 then
game.ReplicatedStorage.Events.Win:FireAllClients()
points.Value = points.Value + reward.Value * 10
print("Winners")
end
end)
The code you have right now, does not automatically work when the “FI” value changes or is updated, you would have to do it in that way ^
I do not think that is the issue, it should still work. By the way @MCCREAP2, so printing anything in the local script does not work? (not talking about inside the remote event, but in general)
I would except there’s another Gui in the game with the exact same script that does run:
local Info = TweenInfo.new(1)
local Tween = game:GetService("TweenService"):Create(script.Parent,Info,{TextTransparency=0})
local Tween2 = game:GetService("TweenService"):Create(script.Parent,Info,{TextTransparency=1})
game.ReplicatedStorage.Events.RemoteAttack.OnClientEvent:Connect(function()
script.Parent.Reckless:Play()
Tween:Play()
wait(2.5)
Tween2:Play()
end)
This one works fine with the same script from StarterGui
print("Testing")
local Info = TweenInfo.new(1)
local Tween = game:GetService("TweenService"):Create(script.Parent,Info,{TextTransparency=0})
local Tween2 = game:GetService("TweenService"):Create(script.Parent,Info,{TextTransparency=1})
game.ReplicatedStorage.Events.Win.OnClientEvent:Connect(function()
script.Parent.Cheer:Play()
Tween:Play()
wait(4.5)
Tween2:Play()
end)
I messed up something in the code it does appear to work, that is my bad. I’m unsure what could be causing your bug I think it’s something simple that were overlooking.
Could it possibly be that the client event does not load fast enough for when the server event sends the signal? Where and when are you firing the start.event? Maybe try adding waits before you fire the events.
if FI.Value < 10 then
task.wait(2)
game.ReplicatedStorage.Events.Win:FireAllClients()
points.Value = points.Value + reward.Value * 10
print("Winners")
else
task.wait(2)
game.ReplicatedStorage.Events.Lose:FireAllClients()
print("Losers")
end
Adding task.wait() in the serverscript? I don’t get the point, I am 100% sure that the events are fired as they are located in ReplicatedStorage. The issue must be on the client side. I would highly recommend to wrap things up and just try using some other methods as the client does not seem to be catching up with the event.