You can write your topic however you want, but you need to answer these questions:
I’m trying to make a script where a sphere appears for 0.5 seconds and then gets destroyed, but when that sphere appears, anybody in it’s range, including myself get caught in it and get hit by it, then using a remote event to fire something on all clients hit by the sphere.
For some reason, the “Touched” function isn’t detecting anything, not me nor anybody, I’ve got 0 clue why.
I tried looking for help here on DevForum but got a lot of Raycast hitbox types which isn’t what I’m making this hitbox. I have another hitbox script which worked fine, and the only difference with the code below and the code that works is A: My other code doesn’t detect the user, and B: I create the hitbox part IN the script, while here I am cloning it from ReplicatedStorage.
The code that I am trying to fix that does NOT work:--
local VoidHitbox = game.ReplicatedStorage.Domain.DomainExpansion.VoidHitbox:Clone()
VoidHitbox.Parent = game.Workspace
VoidHitbox.Position = Dome.Position
local VoidWeld = Instance.new("Weld")
VoidWeld.Parent = HumanoidRP
VoidWeld.Part1 = HumanoidRP
VoidWeld.Part0 = VoidHitbox
---------------------------
VoidHitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Name == "HumanoidRootPart" then
local TargetHum = hit.Parent:FindFirstChild("Humanoid")
local DomainLocalScript = game.ReplicatedStorage.Domain.LocalDomainEvent:Clone()
DomainLocalScript.Parent = hit.Parent
print(hit.Parent.Name)
DomainEvent:FireClient("Expand")
end
end
end)
The code that DOES work:--
local Character = Player.Character or Player.CharacterAdded:Wait()
local Hitbox = Instance.new("Part", Character)
local Weld = Instance.new("Weld")
Weld.Parent = Character.HumanoidRootPart
Weld.Part0 = Hitbox
Weld .Part1 = Character.HumanoidRootPart
Weld.C0 = CFrame.new(0,-5,18)
Hitbox.Parent = Character
Hitbox.Size = Vector3.new(26,22,35)
Hitbox.Anchored = false
Hitbox.CanCollide = false
Hitbox.Massless = true
Hitbox.Transparency = 1
Hitbox.Color = Color3.new(1, 0, 0)
Hitbox.Material = "ForceField"
Hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Name == "HumanoidRootPart" then
if hit.Parent.Name ~= Character.Name then
local TargetHum = hit.Parent:FindFirstChild("Humanoid")
If anybody knows what I did wrong or knows how I can improve, please let me know. I’m doing this for practice and to improve but I’ve hit a brick wall.
I assume that DomainEvent is a RemoteEvent? The syntax for FireClient() is as follows: RemoteEvent:FireClient(player : Player, ... : any?)
You must pass a Player object to FireClient(), and getting the player can be achieved by using Players:GetPlayerFromCharacter():
local PLAYERS = game:GetService("Players")
local playerCharacter = workspace.pretendThisIsAPlayerCharacter
print(PLAYERS:GetPlayerFromCharacter(playerCharacter))
Correct, DomainEvent is a remote event that I’m firing using a tool that’s firing to server. I see what you mean regarding the FireClient, I’ll have to adjust that too. I’m just unsure why my part isn’t being touched in the first place.
I’ve heard of magnitude before just never understood it, I guess I have that to look into as well. I’m relatively new to scripting so a lot of things still don’t make full sense to me like what to do and how to do it better and vice versa, so thank you guys for helping me.
For hitboxes like this I highly recommend using the ZonePlus module by ForeverHD.
From my experience it’s super accurate and has built-in functions for detecting either players (on the server) or localplayer (on the client).
I’ll 100% try that, I’m still new to modules so I don’t really know how they work or even really how to call them. Things like the lightning modules that people use.
Pretty similar yeah. Only difference is that the PartsBoundInRadius one does a spherical area while teh PartsInPart one does a box area (the part that is passed as a parameter to the parts in part function.)
For something like this you would just insert the module in ReplicatedStorage, call it using
Zone = require(ReplicatedStorage:WaitForChild(“Zone”)
and to create the “Zone” (hitbox) do
VoidZone = Zone.new(VoidHitbox)
and replace VoidHitBox.Touched with VoidZone.playerEntered which also returns the player who touched it
From my experience it’s best to avoid touched events wherever possible because they are unreliable/inaccurate. You won’t regret taking the leap to ZonePlus