Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Part that gives points doesn't work properly?

Asked by 6 years ago

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

0
Is your game FE? thefatrat87 18 — 6y
0
Yes MajinBluee 80 — 6y
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. KingLoneCat 2642 — 6y
0
This should be handled on the server. User#19524 175 — 6y

3 answers

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

Using script.Parents to get a player is a bad practice if you are using a local script you need to useLocalPlayer 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!

Ad
Log in to vote
1
Answered by 6 years ago

Hi. The primary reason why this isn't working, is because you are using Local Scripts to change a Server-Side feature in a Filtering Enabled place.

Try using Remove Functions and Events to communicate between Client>Server and vice versa.

This article should help.

https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events

Log in to vote
0
Answered by
OnaKat 444 Moderation Voter
6 years ago

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)

Answer this question