so i i have part and another part, when i spawn the part when pressed e, the part spawns and i put it on another block, my question is how do i add a leader stat when player’s part touched the
my spawn script:
local UIS = game:GetService("UserInputService")
local Character = script.Parent
local Pp = game.ReplicatedStorage:WaitForChild("Pp")
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local CurrentParts = 0
UIS.InputBegan:Connect(function(Key, Chatted)
if Chatted then
return
end
if Key.KeyCode == Enum.KeyCode.E and CurrentParts == 0 then
CurrentParts += 1
Event:FireServer()
end
if Key.KeyCode == Enum.KeyCode.Q and CurrentParts == 1 then
CurrentParts -=1
Pp:FireServer()
end
end)
my server script:
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)))
end)
Pp.OnServerEvent:Connect(function(Player)
local part = workspace.Folder:FindFirstChild(Player.Name.."'s clone")
if not part then
return
end
part:Destroy()
end)
You could create an event that fires when the ClonedPart is touched, check if the part that touched the ClonedPart is some player part, get the player from character and add a point to the player.
Example:
ClonedPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") 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
end
end)
1 Like
where would i put this? the local script or the server script?
On the server script, after this line and before the end.
where would i put the brick’s name?
Please make sure to add a debounce, so the player doesn’t get a million points and the client’s memory doesn’t clog up cause you’re firing events quickly.
1 Like
how would i make it destroy when it touches the brick?
Oh yes! That’s very important! I forgot that XD
You could add hit:Destroy()
after this line to destroy the player part.
local db = false
ClonedPart.Touched:Connect(function(hit)
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
db = true
end
end)
so the whole script should look like this?
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: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)
yes, let me know if it works out
uhh it don’t work, how can i make it so that it touches a specific bricks(maybe make them the same name and make the dummy delete when touched these specific bricks)
btw there is this error:
Touched is not a valid member of Model "Workspace.Folder.foxnoobkite's Noob"
You have to reference the HumanoidRootPart
instead, Touched
does not work on Models it’ll only work on BaseParts
uhh how would i modify it?
would i have to change the brick’s script?(brick = the brick that the part is gonna touch)
Change this
To this
ClonedPart.HumanoidRootPart.Touched:Connect(function(Hit)
how would i
how would I modify this one so that it only works when touched certain bricks
I don’t follow/understand, if you mean you’re wanting to detect when the ClonedPart
Model gets touched at all then you could just do Humanoid.Touched
You’d need to implement checks inside the Touched
Event given to you with a Hit
parameter, and you can check if the Part hit another Part, the Part hit a Player, or the Part hit a UFO or something
like the ClonedPart touch a specific brick and add 1 point then delete itself. (I’m gonna make -=1 for the CurrentParts)