Touch event is not firing

  1. I want the Player to get a Crown when they touch the Crown

  2. The Script works but when I respawn and a new Crown Spawns then the touch event doesnt get Fired

In the Console it prints 1 before the Touched Event line but the Event does not get Fired

3 Likes

What type of script do you use to detect touching the crown ?
Also could you share some of your code ? Its hard to find out whats wrong without knowing how it works.

2 Likes

Im using a Module Script here is the Code

local KingModule = {}

KingModule.Died = function(King: Player)
	local CrownModule = require(game.ServerStorage.ModuleScripts.Crown)
	
	KingModule.RemoveKing(King)
	KingModule.ChangeCurrentKing("")
	
	CrownModule.SpawnCrownToLastKingPosition(15)
	
	print("King died")
end 

local CrownModule = {}

CrownModule.Spawn = function(Position: Vector3)
	local Crown = ServerStorage.Models.MainGame.Crown:Clone()

	Crown.Position = Position
	Crown.Parent = game.Workspace
	
	CrownModule.Float(Crown)
	
	CrownModule.PlayerTookCrown(Crown)
end

CrownModule.PlayerTookCrown = function(Crown: MeshPart)
	print("1")
	Crown.Touched:Connect(function(hit)
		print(hit)
		if hit then
			if hit.Parent:FindFirstChild("Humanoid") then
				if game.Players:FindFirstChild(hit.Parent.Name) and hit.Parent:FindFirstChild("Humanoid").Health > 0 then
					if not KingModule.CheckIsKing(game.Players:FindFirstChild(hit.Parent.Name)) then
						KingModule.MakeKing(game.Players:FindFirstChild(hit.Parent.Name))

						MainModule.PlaySound(game.Players:FindFirstChild(hit.Parent.Name), SoundService.Crown.Success)

						Crown:Destroy()

						CrownModule.FollowPlayer(game.Players:FindFirstChild(hit.Parent.Name))

						return
					end
				end
			end
		end
	end)
end

CrownModule.SpawnCrownToLastKingPosition = function(Height: number)
	if game.Workspace.Game:FindFirstChild("KingPosition") then
		CrownModule.Spawn(game.Workspace.Game:FindFirstChild("KingPosition").Position + Vector3.new(15, Height, 0))
	else
		CrownModule.Spawn(game.Workspace.Map:FindFirstChild("Middle").Position +  Vector3.new(0, Height, 0))
	end
end
1 Like

Have you tried using script instead of ModuleScript ?

1 Like

No but I tried checking if the Touch Event works for the Baseplate and it works but it doesnt work for the Crown

Also for some reason when I touch the Crown the TouchInterest disappears

1 Like

is CanTouch enabled in the crown properties? check in the explorer during a play test

1 Like

yes its enabled
image

verify that the new crown is actually recognized by the script by using print(Crown) in the PlayerTookCrown function

1 Like

I just tried that and the crown gets recognized by the script

1 Like

it might be something with the crown part itself, try replacing it with a normal part to see if that works

1 Like

Last Idea I got is to change position of CrownModule.Spawn and CrownModule.PlayerTookCrown:

CrownModule.PlayerTookCrown = function(Crown: MeshPart)
	print("1")
	Crown.Touched:Connect(function(hit)
		print(hit)
		if hit then
			if hit.Parent:FindFirstChild("Humanoid") then
				if game.Players:FindFirstChild(hit.Parent.Name) and hit.Parent:FindFirstChild("Humanoid").Health > 0 then
					if not KingModule.CheckIsKing(game.Players:FindFirstChild(hit.Parent.Name)) then
						KingModule.MakeKing(game.Players:FindFirstChild(hit.Parent.Name))

						MainModule.PlaySound(game.Players:FindFirstChild(hit.Parent.Name), SoundService.Crown.Success)

						Crown:Destroy()

						CrownModule.FollowPlayer(game.Players:FindFirstChild(hit.Parent.Name))

						return
					end
				end
			end
		end
	end)
end

CrownModule.Spawn = function(Position: Vector3)
	local Crown = ServerStorage.Models.MainGame.Crown:Clone()

	Crown.Position = Position
	Crown.Parent = game.Workspace

	CrownModule.Float(Crown)

	CrownModule.PlayerTookCrown(Crown)
end

Else I don’t know, I am honestly confused by this code.

1 Like

I placed the Script into ServerScriptService instead of StarterCharacterScripts because after the Player dies the Script will be destroyed and the Event cant be Fired thanks for trying to help me tho.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.