Hi, I'm new to scripting and I'm trying to make a king of the hill like game for practice.
So I want to check if a player is touching a part, and if he is every second he will get 1 point, now the problem is that if the player stands still he won't get points if I'm using .Touched event.
That's why I'm trying to use :GetTouching() function but it's not detecting when I touch the part.
this was my first script:
local plate = script.Parent
local Players = game:GetService("Players")
plate.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local plr = hit.Parent
local playerFromCharacter = Players:GetPlayerFromCharacter(plr)
local canGetPoints = playerFromCharacter.canGetPoints
if canGetPoints.Value == true then
playerFromCharacter.leaderstats.Points.Value += 1
canGetPoints.Value = false
wait(1)
canGetPoints.Value = true
end
end
end)
this is my current script which isn't working(it's only detecting when the baseplate is touching it)
local plate = script.Parent
local Players = game:GetService("Players")
while true do
wait ()
local parts = plate:GetTouchingParts()
for i = 1, #parts do
local part = parts[i]
if part.Parent:FindFirstChild("Humanoid") then
local plr = part.Parent
local playerFromCharacter = Players:GetPlayerFromCharacter(plr)
local canGetPoints = playerFromCharacter.canGetPoints
if canGetPoints.Value == true then
playerFromCharacter.leaderstats.Points.Value += 1
canGetPoints.Value = false
wait(1)
canGetPoints.Value = true
end
end
end
end