This code works perfectly when I use it in a normal script but ceases to function as a localscript without giving me any sort of errors or clues. Any help would be greatly appreciated!
Scripts and LocalScripts have been made to act differently. Changing properties from a LocalScript won’t replicate the change to the server and so other players won’t see it if that’s your problem
Local scripts do not work when placed as a descendant of workspace.
By the way heres a smaller version of that script:
local gravel = script.Parent
local texture = script.Parent.Texture
local isTouched = false
local function PlayerTouched()
if isTouched == false then
isTouched = true
repeat
task.wait(0.2)
gravel.Transparency += 0.1
texture.Transparency += 0.1
until
gravel.Transparency == 1
texture.Transparency == 1
gravel.CanCollide = false
task.wait(5)
gravel.Transparency = 0
texture.Transparency = 0
gravel.CanCollide = true
end
end
end
gravel.Touched:Connect(PlayerTouched)
No LocalScripts in the workspace just don’t run so you need to adjust it to work being located in a player related “place” like StarterPlayerScripts
LocalScripts wont run inside certain locations in which Scripts do(for example workspace) although there’re a few exclusions like the player character. LocalScripts run for a single client therefore they wont replicated to the server(unless remotes are used for server communication). Due to the gravel variable at the top, which refers to script.Parent I assume the LocalScript is inside a part in workspace which is probably causing the issue. Instead the code above should be placed inside StarterCharacterScripts which will ensure it runs(I also applied some modifications and cleaned the code, although the behavior should remain the same):
--LocalScript inside StarterCharacterScripts
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
--debounces
local touched = {}
Humanoid.Touched:Connect(function(hit)
--name the gravel parts "gravel"
if hit.Name == "gravel" and not table.find(touched, hit) then
local texture = hit.Texture
table.insert(touched, hit)
for i = 0.1, 1, 0.1 do
hit.Transparency = i
texture.Transparency = i
task.wait(.2)
end
hit.CanCollide = false
task.wait(5)
hit.Transparency = 0
texture.Transparency = 0
hit.CanCollide = true
local index = table.find(touched, hit)
if index then
table.remove(touched, index)
end
end
end)