so, in my game, i’m trying to remake one of the puzzles from UNDERTALE (yeah, the game everyone’s already tired of hearing for 3 years). here’s basically the concept of what i wanted:
basically, if you step on the union, all of the spikes turn invisible, until you step off. @konlon15 helped out with this after i posted about it on reddit, however, while it got the job done (which im very thankful for), it was riddled with messy bugs, specifically, this one:
after stepping on spikes, sometimes it’s possible to have some still be rendered invisible, even when you step back onto them. this only occurs online, as opposed to single-player test mode in studio.
right now, the script konlon made me is here, however, as he described to me, touchended isn’t always a reliable event.
--made by konlon15 for Superkirbylover
local Players = game:GetService("Players")
local waittime = 0.15
local Ruins = workspace:WaitForChild("spikepath_ruins")
local Spikes = Ruins:WaitForChild("safespikes")
function CheckSpikeTransparency(TouchingChars, Spikes)
local Count = (function() local c = 0 for i, v in pairs(TouchingChars) do c = 1 end return c end)()
--the above calls an anonymous function and then counts all touchingchars
if Count >= 1 then -- 1 or more players stand on the base
for i, Spike in pairs(Spikes) do
Spike.Transparency = 1
end
else -- 0 players on the base
for i, Spike in pairs(Spikes) do
Spike.Transparency = 0
end
end
end
for i, Trap in pairs(Spikes:GetChildren()) do
--i is the number we're on
--Trap is the safespiketrap
local Base = Trap:FindFirstChild("base")
local TouchingChars = {} -- this is a lua table
if Base then
local Spikes = (function() local t = {} for i, v in pairs(Trap:GetChildren()) do if v.Name == "spike" then table.insert(t, v) end end return t end)()
Base.Touched:Connect(function(Part)
print("start", Part, Part.Parent)
local Character = Part.Parent
if Character:FindFirstChild("Humanoid") then
TouchingChars[Character] = true
CheckSpikeTransparency(TouchingChars, Spikes)
-- this is the same as doing this:
-- local Touching_Chars = {
-- all the other players standing on the base
-- [game.workspace.konlon15] = true
-- }
end
end)
Base.TouchEnded:Connect(function(Part)
print("end", Part, Part.Parent)
local Character = Part.Parent
if Character:FindFirstChild("Humanoid") then
TouchingChars[Character] = nil --this removes the character from the table!
delay(waittime, function()
if TouchingChars[Character] == nil then
CheckSpikeTransparency(TouchingChars, Spikes)
TouchingChars = {} --this resets the table totally. good? maybe.
end
end)
end
end)
end
end
is there ways for me to go about fixing this? do i have to make a whole, new script, or just modify the current one?
(i guess it’s important to mention i have scripting experience, however, it’s not 100% advanced. only slightly.)