Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Part that gives points doesn't work properly?

Hello, So I'm trying to make a part that gives you points when you touch it and it has a cooldown. The part's size is the size of an ocean and when I jump into the ocean it gives me only 1 point and when I jump again it gives me 1 points, So it just gives me points when I jump into the ocean and when I'm jumping in the ocean.

I tried doing it in a server script and it does the same thing.

Local Script (Inside PlayerGui):

local Part = game.Workspace.Part

Part.Touched:Connect(function()
	if Debounce == false then
		Debounce = true
		wait(1)
		script.Parent.Parent.Parent:WaitForChild("leaderstats").Points.Value = 	script.Parent.Parent.Parent:WaitForChild("leaderstats").Points.Value + 1
		Debounce = false
	end
end)

I would really appreciate it if you will help me with my problem, Plus I'll accept your answer.

Thanks, MajinBluee

4 comments

0

Is your game FE?

0

Yes

0

Did you say that it doesn't work at all? You need to be more clear please because I thought you meant that it doesn't work the way you want it to work.

0

This should be handled on the server.

3 answers

✓ Accepted answer

Using script.Parents to get a player is a bad practice if you are using a local script you need to use LocalPlayer to get player. If this script doesn't work, you might have to use ServerSided script inside a part!

Fix to your LocalScript:

local Part = game.Workspace:WaitForChild("Part") -- Name of your part
local Player = game:GetService("Players").LocalPlayer
local Debounce = false -- Prevents a ton of hits at once
local leaderstats = Player:WaitForChild("leaderstats")

---------------------------------------------------------------------------------------------------------------------------
local PointsToAdd = 1 --  Points to be added when part touched
---------------------------------------------------------------------------------------------------------------------------

wait(0.1)

Part.Touched:Connect(function()

	wait()
    if not Debounce then

        Debounce = true

        wait(1)
       	leaderstats.Points.Value = leaderstats.Points.Value + PointsToAdd

    end

	Debounce = false

end)

Put this inside a part:

-- Dont put this inside an LocalScript!
-- Put in "Normal" script

local Debounce = false

local PointsToAdd = 1

script.Parent.Touched:Connect(function(hit)

	if not Debounce then
		Debounce = true

		hit.Parent:WaitForChild("leaderstats").Points.Value = hit.Parent:WaitForChild("leaderstats").Points.Value + PointsToAdd

		wait(0.25)

	end

	wait(0.5)

	Debounce = false
end)

See what works for you! Hope that I've helped you!

Put this server script in the part


local PARTCOLOR = 0,255,0 --PUT PART COLOR HERE

local part = script.Parent
local red = 255,0,0

function onTouched(hit)
if part.BrickColor ~= red then
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    local point = plr.leaderstats.Points
        
    point.Value = point.Value + 1
    part.BrickColor = Color3.new(255,0,0)
else
    wait(3)
    part.BrickColor = PARTCOLOR
end
end

part.Touched:Connect(onTouched)

This discussion is preserved as it was. New answers, comments, and votes are closed.