-
I want the Player to get a Crown when they touch the Crown
-
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
I want the Player to get a Crown when they touch the Crown
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
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.
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
Have you tried using script instead of ModuleScript ?
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
is CanTouch
enabled in the crown properties? check in the explorer during a play test
yes its enabled
verify that the new crown is actually recognized by the script by using print(Crown)
in the PlayerTookCrown
function
I just tried that and the crown gets recognized by the script
it might be something with the crown part itself, try replacing it with a normal part to see if that works
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.
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.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.