Hello!
–Introduction–
I’m making a game like slap battles but instead of slapping, it’s punching.
I’m making a glove called “Country Glove”, which pops up an image of a country flag every time you get hit by it.
–The problem–
I try to make the country flag disable using USA.Enabled = false on a server script, and I realized that you cannot do that on a server script, so I used :FireClient and .OnClientEvent and it seems to not work!
–Server Script–
local DebounceTable = {}
script.Parent:WaitForChild("Handle").Touched:Connect(function(objectThatTouchesTheHitbox)
if objectThatTouchesTheHitbox.Parent then
if objectThatTouchesTheHitbox.Parent:FindFirstChild("Humanoid") then
if DebounceTable[objectThatTouchesTheHitbox.Parent] == true then return end
DebounceTable[objectThatTouchesTheHitbox.Parent] = true
local player = script:FindFirstAncestorWhichIsA"Player" or game:GetService"Players":GetPlayerFromCharacter(script.Parent.Parent)
local PunchKB = require(game.ServerScriptService.PunchKBCountry)
PunchKB:knockBack(player.Character, objectThatTouchesTheHitbox.Parent)
player.leaderstats.Brawls.Value += 1
script.Parent.VineBoomSoundEffect:Play()
local randomNumber = math.random(1,6)
if randomNumber == 1 then
local enemy = objectThatTouchesTheHitbox.Parent
local pEnemy = game.Players:GetPlayerFromCharacter(enemy)
pEnemy.PlayerGui.USA.Enabled = true
wait(2)
game.ReplicatedStorage.USAReplicate:FireClient(pEnemy)
end
if randomNumber == 2 then
local enemy = objectThatTouchesTheHitbox.Parent
local pEnemy = game.Players:GetPlayerFromCharacter(enemy)
pEnemy.PlayerGui.Canada.Enabled = true
wait(2)
game.ReplicatedStorage.CanadaReplicate:FireClient(pEnemy)
end
if randomNumber == 3 then
local enemy = objectThatTouchesTheHitbox.Parent
local pEnemy = game.Players:GetPlayerFromCharacter(enemy)
pEnemy.PlayerGui.Russia.Enabled = true
wait(2)
game.ReplicatedStorage.RussiaReplicate:FireClient(pEnemy)
end
if randomNumber == 4 then
local enemy = objectThatTouchesTheHitbox.Parent
local pEnemy = game.Players:GetPlayerFromCharacter(enemy)
pEnemy.PlayerGui.Ukraine.Enabled = true
wait(2)
game.ReplicatedStorage.UkraineReplicate:FireClient(pEnemy)
end
if randomNumber == 5 then
local enemy = objectThatTouchesTheHitbox.Parent
local pEnemy = game.Players:GetPlayerFromCharacter(enemy)
pEnemy.PlayerGui.Brazil.Enabled = true
wait(2)
game.ReplicatedStorage.BrazilReplicate:FireClient(pEnemy)
end
if randomNumber == 6 then
local enemy = objectThatTouchesTheHitbox.Parent
local pEnemy = game.Players:GetPlayerFromCharacter(enemy)
pEnemy.PlayerGui.Mexico.Enabled = true
wait(2)
game.ReplicatedStorage.MexicoReplicate:FireClient(pEnemy)
end
wait(1)
DebounceTable[objectThatTouchesTheHitbox.Parent] = nil
end
end
end)
local randomNumber = math.random(1,6)
if randomNumber == 1 then
local enemy = objectThatTouchesTheHitbox.Parent
local pEnemy = game.Players:GetPlayerFromCharacter(enemy)
pEnemy.PlayerGui.USA.Enabled = true
wait(2)
game.ReplicatedStorage.USAReplicate:FireClient(pEnemy)
end
if randomNumber == 2 then
local enemy = objectThatTouchesTheHitbox.Parent
local pEnemy = game.Players:GetPlayerFromCharacter(enemy)
pEnemy.PlayerGui.Canada.Enabled = true
wait(2)
game.ReplicatedStorage.CanadaReplicate:FireClient(pEnemy)
end
if randomNumber == 3 then
local enemy = objectThatTouchesTheHitbox.Parent
local pEnemy = game.Players:GetPlayerFromCharacter(enemy)
pEnemy.PlayerGui.Russia.Enabled = true
wait(2)
game.ReplicatedStorage.RussiaReplicate:FireClient(pEnemy)
end
if randomNumber == 4 then
local enemy = objectThatTouchesTheHitbox.Parent
local pEnemy = game.Players:GetPlayerFromCharacter(enemy)
pEnemy.PlayerGui.Ukraine.Enabled = true
wait(2)
game.ReplicatedStorage.UkraineReplicate:FireClient(pEnemy)
end
if randomNumber == 5 then
local enemy = objectThatTouchesTheHitbox.Parent
local pEnemy = game.Players:GetPlayerFromCharacter(enemy)
pEnemy.PlayerGui.Brazil.Enabled = true
wait(2)
game.ReplicatedStorage.BrazilReplicate:FireClient(pEnemy)
end
if randomNumber == 6 then
local enemy = objectThatTouchesTheHitbox.Parent
local pEnemy = game.Players:GetPlayerFromCharacter(enemy)
pEnemy.PlayerGui.Mexico.Enabled = true
wait(2)
game.ReplicatedStorage.MexicoReplicate:FireClient(pEnemy)
end
This is the code that I was struggling with.
–Client Script for USA Flag–
game.ReplicatedStorage.USAReplicate.OnClientEvent:Connect(function(pEnemy)
pEnemy.PlayerGui.USA.Enabled = false
end)
How do I fix this?