You can do
if hit.Name == "PartNameYouWantToTouch" then
--Add 1 point, then destroy the Model
end
You can do
if hit.Name == "PartNameYouWantToTouch" then
--Add 1 point, then destroy the Model
end
where would i put the script in? like after
ClonedPart:SetPrimaryPartCFrame(CFrame.new(HRP.CFrame.Position + (HRP.CFrame.LookVector * 5)))
?
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Pp = game.ReplicatedStorage:WaitForChild("Pp")
Event.OnServerEvent:Connect(function(Player)
local Character = Player.Character
local HRP = Character:WaitForChild("HumanoidRootPart")
local ClonedPart = game.ReplicatedStorage.Part:Clone()
ClonedPart.Parent = workspace.Folder
ClonedPart.Name = Player.Name.."'s Noob"
ClonedPart:MakeJoints() --Still don't understand why this is deprecated
ClonedPart.PrimaryPart = ClonedPart.Torso --This is called first before calling the PrimaryPartCFrame function
ClonedPart:SetPrimaryPartCFrame(CFrame.new(HRP.CFrame.Position + (HRP.CFrame.LookVector * 5)))
local db = false
ClonedPart.Touched:Connect(function(hit)
if hit.Parent.Name == "PartNameYouWantToDetect" then
--Add a point here then destroy the model
ClonedPart:Destroy()
end
if hit.Parent:FindFirstChild("Humanoid") and db == false and hit.Name == "PlayerPartName" then -- If is a player and is a player part
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Points = Player.leaderstats.YourValueHere
Points.Value += 1 -- Add a point to the player
hit:Destroy()
db = true
end
end)
end)
Pp.OnServerEvent:Connect(function(Player)
local part = workspace.Folder:FindFirstChild(Player.Name.."'s Noob")
if not part then
return
end
part:Destroy()
end)
Just be sure to change the name of what part you want to detect
can i do this in like a folder? bc i have mutiple bricks
If you mean attempting to detect for specific parts, and not just 1 then yes
Create a table after your define your variables, which will hold all of the names for the Parts you want to detect when the Touched
Event starts to fire & use table.find
to search if the HitPart is equal to 1 of the parts inside the table
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Pp = game.ReplicatedStorage:WaitForChild("Pp")
local Parts = {"Part1", "Part2", "Part3", "Part4"}
Event.OnServerEvent:Connect(function(Player)
local Character = Player.Character
local HRP = Character:WaitForChild("HumanoidRootPart")
local ClonedPart = game.ReplicatedStorage.Part:Clone()
ClonedPart.Parent = workspace.Folder
ClonedPart.Name = Player.Name.."'s Noob"
ClonedPart:MakeJoints() --Still don't understand why this is deprecated
ClonedPart.PrimaryPart = ClonedPart.Torso --This is called first before calling the PrimaryPartCFrame function
ClonedPart:SetPrimaryPartCFrame(CFrame.new(HRP.CFrame.Position + (HRP.CFrame.LookVector * 5)))
local db = false
ClonedPart.Touched:Connect(function(hit)
if table.find(Parts, hit.Parent.Name) then
--Add a point here then destroy the model
ClonedPart:Destroy()
end
if hit.Parent:FindFirstChild("Humanoid") and db == false and hit.Name == "PlayerPartName" then -- If is a player and is a player part
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Points = Player.leaderstats.YourValueHere
Points.Value += 1 -- Add a point to the player
hit:Destroy()
db = true
end
end)
end)
Pp.OnServerEvent:Connect(function(Player)
local part = workspace.Folder:FindFirstChild(Player.Name.."'s Noob")
if not part then
return
end
part:Destroy()
end)
how would i do -= 1 the currentpart that is in the other script?
Wait I just realized this is ALL INSIDE A ONSERVEREVENT
You could literally reference the Player’s leaderstats as this:
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Pp = game.ReplicatedStorage:WaitForChild("Pp")
local Parts = {"Part1", "Part2", "Part3", "Part4"}
Event.OnServerEvent:Connect(function(Player)
local stats = Player.leaderstats
local Character = Player.Character
local HRP = Character:WaitForChild("HumanoidRootPart")
local ClonedPart = game.ReplicatedStorage.Part:Clone()
ClonedPart.Parent = workspace.Folder
ClonedPart.Name = Player.Name.."'s Noob"
ClonedPart:MakeJoints() --Still don't understand why this is deprecated
ClonedPart.PrimaryPart = ClonedPart.Torso --This is called first before calling the PrimaryPartCFrame function
ClonedPart:SetPrimaryPartCFrame(CFrame.new(HRP.CFrame.Position + (HRP.CFrame.LookVector * 5)))
local db = false
ClonedPart.Touched:Connect(function(hit)
if table.find(Parts, hit.Parent.Name) then
stats.YourValueHere.Value += 1
ClonedPart:Destroy()
end
if hit.Parent:FindFirstChild("Humanoid") and db == false and hit.Name == "PlayerPartName" then -- If is a player and is a player part
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Points = Player.leaderstats.YourValueHere
Points.Value += 1 -- Add a point to the player
hit:Destroy()
db = true
end
end)
end)
Pp.OnServerEvent:Connect(function(Player)
local part = workspace.Folder:FindFirstChild(Player.Name.."'s Noob")
if not part then
return
end
part:Destroy()
end)
do i have to change my leaderstat script? its like this:
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Pp = game.ReplicatedStorage:WaitForChild("Pp")
local Parts = {"Part1", "Part2", "Part3", "Part4"}
Event.OnServerEvent:Connect(function(Player)
local Character = Player.Character
local HRP = Character:WaitForChild("HumanoidRootPart")
local ClonedPart = game.ReplicatedStorage.Part:Clone()
ClonedPart.Parent = workspace.Folder
ClonedPart.Name = Player.Name.."'s Noob"
ClonedPart:MakeJoints() --Still don't understand why this is deprecated
ClonedPart.PrimaryPart = ClonedPart.Torso --This is called first before calling the PrimaryPartCFrame function
ClonedPart:SetPrimaryPartCFrame(CFrame.new(HRP.CFrame.Position + (HRP.CFrame.LookVector * 5)))
local db = false
ClonedPart.Touched:Connect(function(hit)
if table.find(Parts, hit.Parent.Name) then
--Add a point here then destroy the model
ClonedPart:Destroy()
end
if hit.Parent:FindFirstChild("Humanoid") and db == false and hit.Name == "Brick" then -- If is a player and is a player part
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Points = Player.leaderstats.Points
Points.Value += 1 -- Add a point to the player
hit:Destroy()
db = true
end
end)
end)
Pp.OnServerEvent:Connect(function(Player)
local part = workspace.Folder:FindFirstChild(Player.Name.."'s Noob")
if not part then
return
end
part:Destroy()
end)