Gui Code not running

Hello. For some weird reason, some code does not run, but it prints still “Worked”. It does not error.
Client Script

local playercharacter = game.Players.LocalPlayer.Character
local playericon = script.Parent.Player
local ClientKill = game.ReplicatedStorage.PlayerSmash
local ClientWinner = game.ReplicatedStorage.WinnerWinnerChickenDinner
local focus = ""
while true do
	wait(0)
	local position = UDim2.new(playercharacter.Ball.Position.X/1958, 0, playercharacter.Ball.Position.Z/1958, 0)
	playericon:TweenPosition(position, Enum.EasingDirection.In, Enum.EasingStyle.Sine,   0)
	ClientKill.OnClientEvent:Connect(function(Killer, Victim)
		if Victim.Name == game.Players.LocalPlayer.Name then
			playercharacter = Killer.Character
			print("worked")
			playericon.BackgroundColor3 = Color3.new(0.882353, 0, 0)
			focus = Killer.Name
		elseif focus == Victim.Name then
			playercharacter = Killer.Character
			focus = Killer.Name
		end
	end)
	ClientWinner.OnClientEvent:Connect(function(Winner)
		playericon.BackgroundColor3 = Color3.new(1, 0.968627, 0.054902)
		playercharacter = game.Workspace:FindFirstChild(Winner)
	end)
end

Server script:

local TweenService = game:GetService("TweenService")
local ball = script.Parent.Ball
local tweenInfo = TweenInfo.new(1) 
local cankill = true
local ClientKill = game.ReplicatedStorage.PlayerSmash
local scale = 0
local function chomp(hitobject)
	local h =hitobject.Parent:FindFirstChild("Humanoid")
	if h and cankill then
		local DeadTeam = game.Teams:FindFirstChild("Dead")
		local enemyplayer = game.Players:FindFirstChild(h.Parent.Name)
		local enemyball = h.Parent.Ball
		local playersnowvalue = game.Players:FindFirstChild(ball.Parent.Name).leaderstats.Snow
		local playerkillvalue = game.Players:FindFirstChild(ball.Parent.Name).leaderstats["☠ Kills ☠"]
		local enemysnowvalue = game.Players:FindFirstChild(h.Parent.Name).leaderstats.Snow
		if playersnowvalue.Value > enemysnowvalue.Value then
			cankill = false
			scale = 0
			enemyball.CanTouch = false
			local tween = TweenService:Create(h.Parent.Ball, tweenInfo, {Size = Vector3.new(0, 0, 0)})
			tween:Play()
			tween.Completed:Connect(function()
			h.Health = 0
			playersnowvalue.Value += enemysnowvalue.Value
			playerkillvalue.Value += 1
			enemyplayer.Team = DeadTeam
			ClientKill:FireAllClients(game.Players:FindFirstChild(ball.Parent.Name), enemyplayer)	
			cankill = true
			if playersnowvalue.Value - enemysnowvalue.Value < 5 and playersnowvalue.Value >= 5 then
					scale = 4
			elseif playersnowvalue.Value - enemysnowvalue.Value < 12 and playersnowvalue.Value >= 12 then
					scale = 5
			elseif playersnowvalue.Value - enemysnowvalue.Value < 23 and playersnowvalue.Value >= 23 then
					scale = 6
			elseif playersnowvalue.Value - enemysnowvalue.Value < 37 and playersnowvalue.Value >= 37 then
					scale = 7
			elseif playersnowvalue.Value - enemysnowvalue.Value < 46 and playersnowvalue.Value >= 46 then
					scale = 8
			elseif playersnowvalue.Value - enemysnowvalue.Value < 54 and playersnowvalue.Value >= 54 then
					scale = 9
			elseif playersnowvalue.Value - enemysnowvalue.Value < 63 and playersnowvalue.Value >= 63 then
					scale = 10
			end
				if scale ~= 0 then
					local tween = TweenService:Create(ball, tweenInfo, {Size = Vector3.new(scale, scale, scale)})
					tween:Play()
				end
			end)
		end
	end
end
ball.Touched:Connect(chomp)

Oddly, this approach works with a camera script

Try changing the localscript to

local playercharacter = game.Players.LocalPlayer.Character
local playericon = script.Parent.Player
local ClientKill = game.ReplicatedStorage.PlayerSmash
local ClientWinner = game.ReplicatedStorage.WinnerWinnerChickenDinner
local focus = ""

local position = UDim2.new(playercharacter.Ball.Position.X/1958, 0, playercharacter.Ball.Position.Z/1958, 0)
playericon:TweenPosition(position, Enum.EasingDirection.In, Enum.EasingStyle.Sine,   0)
ClientKill.OnClientEvent:Connect(function(Killer, Victim)
	if Victim.Name == game.Players.LocalPlayer.Name then
		playercharacter = Killer.Character
		print("worked")
		playericon.BackgroundColor3 = Color3.new(0.882353, 0, 0)
		focus = Killer.Name
	elseif focus == Victim.Name then
		playercharacter = Killer.Character
		focus = Killer.Name
	end
end)
ClientWinner.OnClientEvent:Connect(function(Winner)
	playericon.BackgroundColor3 = Color3.new(1, 0.968627, 0.054902)
	playercharacter = game.Workspace:FindFirstChild(Winner)
end)
1 Like

Didn’t work, and it broke my minimap even more.
Also tried this and it didn’t work:

local playercharacter = game.Players.LocalPlayer.Character

local playericon = script.Parent.Player

local ClientKill = game.ReplicatedStorage.PlayerSmash

local ClientWinner = game.ReplicatedStorage.WinnerWinnerChickenDinner

local focus = ""

game:GetService("RunService").RenderStepped:connect(function()

ClientKill.OnClientEvent:Connect(function(Killer, Victim)

if Victim.Name == game.Players.LocalPlayer.Name then

playercharacter = Killer.Character

print("worked")

playericon.BackgroundColor3 = Color3.new(0.882353, 0, 0)

focus = Killer.Name

elseif focus == Victim.Name then

playercharacter = Killer.Character

focus = Killer.Name

end

end)

ClientWinner.OnClientEvent:Connect(function(Winner)

playericon.BackgroundColor3 = Color3.new(1, 0.968627, 0.054902)

playercharacter = game.Workspace:FindFirstChild(Winner)

end)

wait(0)

local position = UDim2.new(playercharacter.Ball.Position.X/1958, 0, playercharacter.Ball.Position.Z/1958, 0)

playericon:TweenPosition(position, Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0)

end)
1 Like

I don’t know what to do. Can someone help please? It should be great! Help plz

1 Like

What is the code that is not running, and what is supposed to happen compared what is currently happening?

Also, is there any reason you’re connecting your events inside of a loop in the client script?

1 Like

What’s supposed to happen is that the minimap stops showing the local player and shows the killer instead. What happens is the focus player never changes and it shows where the player re spawned (under the map.) The reason the on client events are in a loop is because this was a problem with my camera script and the camera not being focused on the killer.

1 Like

Nevermind, found the problem. Gui.resetonspawn was equal to true

2 Likes