What do you want to achieve?
I’m working on an obby game, and one of the obstacles is a fading platform, which disappear after a certain amount of time. I want these platforms to be client-sided instead of server-sided. The reason why I want it to be client-sided is that if it was to be server-sided, if one person activates the fading platform, then everyone sees the platform fade, which causes the problem of everyone needing to go one at a time. If it was client-sided I would assume that if one person activates it on their client, it wouldn’t effect other players or the server.
What is the issue?
It works, but only one platform can fade at a time. This is probably due to the solution I’m using.
What solutions have you tried so far?
In the video above, I’m using remote events. I have looked on the developer hub/forum, and haven’t really found anything similar.
Code:
Script in ServerScriptService:
local cs = game:GetService("CollectionService")
local fadingPart = cs:GetTagged("FadingPart")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local remoteEvent = ReplicatedStorage:WaitForChild("FadingEvent")
for i, v in pairs(fadingPart) do
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = Players:GetPlayerFromCharacter(hit.Parent)
remoteEvent:FireClient(player, v)
end
end)
end
LocalScript in StarterPlayerScripts:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("FadingEvent")
local Players = game:GetService("Players")
local isTouched = false
local function fadingPart(v)
if not isTouched then
isTouched = true
for count = 1, 10 do
v.Transparency = count / 10
wait(0.1)
end
v.CanCollide = false
wait(3)
v.CanCollide = true
v.Transparency = 0
isTouched = false
end
end
remoteEvent.OnClientEvent:Connect(fadingPart)
That’s pretty much the same thing as my code, except that I use CollectionService instead of making a script for every individual part. Wouldn’t that produce the same result, as each individual script is still firing one individual LocalScript? I’ll try and test it and post my results if it works or not either way.
I’ve tested it and it still doesn’t work. It produces a different error, but I can probably fix that. The difference is that this immediately changes the transparency, and also doesn’t restore it after a certain time. I want my part to gradually fade until it becomes fully transparent, and only after 3 seconds, it returns. That’s where my problem is with my script. My localscript works perfectly the first time, however on the second time, it doesn’t, as my localscript is still on debounce and usually on the wait(3) part of my script.
tl;dr This doesn’t really solve my problem, and it might need a new approach altogether.
You can just removed the isTouched debounce as it is not necessary in this situation.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("FadingEvent")
local Players = game:GetService("Players")
local function fadingPart(v)
for count = 1, 10 do
v.Transparency = count / 10
wait(0.1)
end
v.CanCollide = false
wait(3)
v.CanCollide = true
v.Transparency = 0
end
remoteEvent.OnClientEvent:Connect(fadingPart)
I managed to fix it (I think), after modifying the script a bit. Edit: It works.
local remoteEvent = ReplicatedStorage:WaitForChild("FadingEvent")
local Players = game:GetService("Players")
local function fadingPart(v)
if v.Transparency == 0 then
for count = 1, 10 do
v.Transparency = count / 10
wait(0.1)
end
v.CanCollide = false
wait(3)
v.CanCollide = true
v.Transparency = 0
end
end
remoteEvent.OnClientEvent:Connect(fadingPart)```
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("FadingEvent")
local Players = game:GetService("Players")
local isTouched = false
local function fadingPart(v)
if not isTouched then
isTouched = true
for count = 1, 10 do
v.Transparency = count / 10
wait(0.1)
end
v.CanCollide = false
wait(3)
v.CanCollide = true
for count = 1, 10 do
v.Transparency = count * 10
wait(0.1)
end
isTouched = false
end
end
remoteEvent.OnClientEvent:Connect(fadingPart)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("FadingEvent")
local Players = game:GetService("Players")
local Debounce = {}
local function fadingPart(v)
if not Debounce[v] then
Debounce[v] = true
for count = 1, 10 do
v.Transparency = count / 10
wait(0.1)
end
v.CanCollide = false
wait(3)
v.CanCollide = true
v.Transparency = 0
Debounce[v] = nil
end
end
remoteEvent.OnClientEvent:Connect(fadingPart)