As DesiredRep commented, you need to use Client Event, which is a part of Replicated Events (and Functions)
You will need the LocalScript you already have, as well as a Server Script within ServerScriptServices
For this example, I used a Remote Event inside Replicated Storage named "RemoteEvent"
LocalScript
local player = game.Players.LocalPlayer
local background = script.Parent.Background
local text = background.PlayerName
local debounce = true
script.Parent.Parent = player.PlayerGui
local playername = player.Character:WaitForChild("PlayerName")
local remote = game.ReplicatedStorage.RemoteEvent
remote.OnClientEvent:Connect(function(msg)
print(msg)
if msg == "TweenOut" then
script.Parent.Background:TweenPosition(UDim2.new(0.187, 0, 0, 0), "Out", "Back", 2)
text.Text = (playername.Value.." Wins!")
elseif msg == "TweenIn" then
script.Parent.Background:TweenPosition(UDim2.new(0.187, 0, -1, 0), "In", "Back", 2)
end
end)
while true do
local stringvalue = player.Character:FindFirstChild("PlayerName")
if stringvalue ~= nil then
if debounce == false then return end
debounce = false
print("Loop Start")
function getplayername()
if player and playername then
print("Function Start")
playername:Destroy()
remote:FireServer("Out")
wait(5)
remote:FireServer("In")
wait(2)
debounce = true
end
end
getplayername()
else
wait(1)
end
end
Server Script
local remote = game.ReplicatedStorage.RemoteEvent
remote.OnServerEvent:Connect(function(player, setup)
print(setup)
if setup == "Out" then
remote:FireAllClients("TweenOut")
elseif setup == "In" then
remote:FireAllClients("TweenIn")
end
end)
The FireAllClients event can be used to make this occur for all players in the game. The reason you have to send it to the server first is so that it can be then sent to all clients, not just the one player. There is not FireAllClients on the Client-Side.
3 comments
try using client event
How do I do that?
here is a helpful guide to events https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events