I want this script to damage all other players other than the player that first touched it, but the touched event isn’t even running, I’m also getting no errors in output so idk what’s wrong.
local debounce = false
local plr = game.Players.LocalPlayer
local pee = 0
script.Parent.Touched:Connect(function(hit)
print("hey")
if hit.Parent:FindFirstChild("Humanoid") then
if pee == 0 then
hit.Parent.Parent.Name = pee
else
if pee == hit.Parent.Parent.Name then
print("hi")
return end
end
else
if debounce == false then
debounce = true
hit.Parent.Parent.Humanoid.Health = hit.Parent.Parent.Humanoid.Health - 50
end
end
end)
Sorry if it takes me a while to respond to your replys
2 Likes
You’ve made sure that this is a server script & not a local script right?
2 Likes
Like @Limited_Unique said, if it’s a LocalScript it cannot be parented to the Part, a child of workspace. If it’s a server script, line 2 will be the issue as you cannot define Player as game.Players.LocalPlayer
.
1 Like
The player object is incorrectly defined & isn’t even being used anyway but if you do need the player object then the following will work inside a server script parented to the part.
local players = game:GetService("Players")
local debounce = false
local pee = 0
script.Parent.Touched:Connect(function(hit)
print("hey")
local player
local character
local humanoid
if hit.Parent:FindFirstChild("Humanoid") then
character = hit.Parent
player = players:GetPlayerFromCharacter(character)
humanoid = character.Humanoid
if pee == 0 then
hit.Parent.Parent.Name = pee
elseif pee == hit.Parent.Parent.Name then
print("hi")
return
end
if debounce == false then
debounce = true
humanoid.Health -= 50
end
end
end)
To add onto this, you could also just change it to Humanoid:TakeDamage(50)
I just noticed that hit.Parent.Parent.Name = pee
is an attempt to assign the value of the variable “pee” as the value of the property “Name” of the player object which is unassignable.
local players = game:GetService("Players")
local debounce = false
local pee = 0
script.Parent.Touched:Connect(function(hit)
print("hey")
local player
local character
local humanoid
if hit.Parent:FindFirstChild("Humanoid") then
character = hit.Parent
player = players:GetPlayerFromCharacter(character)
humanoid = character.Humanoid
if pee == 0 then
pee = hit.Parent.Parent.Name
elseif pee == hit.Parent.Parent.Name then
print("hi")
return
end
if debounce == false then
debounce = true
humanoid.Health -= 50
end
end
end)
Quick fix to that previous issue. This time the value of the variable named “pee” is assigned the value of the property named “Name” of the player object.
Final cleanup of the previous block of code:
local players = game:GetService("Players")
local debounce = false
local pee = 0
script.Parent.Touched:Connect(function(hit)
print("hey")
local player
local character
local humanoid
if hit.Parent:FindFirstChild("Humanoid") then
character = hit.Parent
player = players:GetPlayerFromCharacter(character)
humanoid = character.Humanoid
if pee == 0 then
pee = player.Name
elseif pee == player.Name then
print("hi")
return
end
if debounce == false then
debounce = true
humanoid.Health -= 50
end
end
end)
Player object is directly referenced using its declared variable.
Dude ik im an idiot but you didn’t have to do all of that, and it is a server script btw
It doesn’t work, but its most likely a problem my side again, because I’m an idiot.
Video of what the part is doing - https://medal.tv/clips/68984151/d13379uEAnPm?invite=cr-MSxwa0YsMjQ5MTMwNTks
script that spawns orb, local script in startercharecterscripts
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local debounce = false
local original = game.ReplicatedStorage.Orb
local copy = original:Clone()
local pee = 0
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
if debounce == false then
debounce = true
copy.Parent = game.Workspace
repeat
copy.Position = player.Character.HumanoidRootPart.Position
copy.Size = Vector3.new(pee, pee, pee)
pee = pee + 1
wait()
until copy.Size == Vector3.new(50, 50, 50)
wait(3)
pee = 0
copy:Destroy()
copy = original:Clone()
wait(0.1)
debounce = false
end
end
end)
I’m not asking you to rewrite the whole script just tell me what’s wrong
What about it doesn’t work? From checking out the video I see that the orb is produced.
For future reference game.Players.LocalPlayer is only defined in local scripts, in other words the local player must be fetched in some other way from a server script.
I mean the touched script doesnt work.
You didn’t share a Touched script, just an InputBegan script. Can you provide a little more info please?
Scroll up… That script doesn’t work, I showed you the input began script to see if that had anything to do with it not working
I solved it, your not supposed to clone stuff with a local script that’s inside of StarterCharscripts so I just added a remote event