How can I modify this to add more if touching, since it is located inside a ServerScriptService. I have a script that uses a RemoteEvent so that when the player hits a button, it uses the RemoteEvent to update leaderstats by one for a simulator game. I have a zone that if your in it, it changes it by more than one, so how can I do it. ServerScriptService cannot store parts.
Script (It just changes by one, doesn’t detect if player is touching certain part):
local debounce = false
game.ReplicatedStorage.Remote.OnServerEvent:Connect(function(player)
if debounce == false then
player.leaderstats.Splits.Value += 1
debounce = true
wait(1.4)
debounce = false
end
end)
You would do it just like you would in any other script
-- in SSS
local newPart = Instance.new("Part")
newPart.Parent = workspace
newPart.Transparency = 1
newPart.CanCollide = false
newPart.Anchored = true
newPart.CFrame = --whatever you want here
newPart.Touched:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") then
-- technically not required but i like only doing the HRP
-- mostly so players with like big wings won't trigger it sooner
if part.Name == "HumanoidRootPart" then
reward = reward + 1
end
end
end)
I’ve written a script that checks if for a humanoid, through a part in the workspace. Everything works, except the connect function (that connects the onTouched function)
Code:
local debounce = false
game.ReplicatedStorage.Remote.OnServerEvent:Connect(function(player)
if debounce == false then
local function onTouched(Obj)
local h = Obj.Parent.Parent.Workspace.Part:FindFirstChild("Humanoid")
if h then
player.leaderstats.Splits.Value += 1
end
end
script.Parent.Parent.Workspace.Part:Connect(onTouched)
end
end)
No error this time, I also changed the Obj to script.
Code:
local debounce = false
game.ReplicatedStorage.Remote.OnServerEvent:Connect(function(player)
if debounce == false then
local function onTouched(Obj)
local h = script.Parent.Parent.Workspace.Part:FindFirstChild("Humanoid")
if h then
player.leaderstats.Splits.Value += 1
end
end
script.Parent.Parent.Workspace.Part.Touched:Connect(onTouched)
end
end)