LocalScript not running upon PlayerTouched()

No errors in output, the goal of the script is to have the player (local) touch a brick and have a certain amount of time before it completely fades and has its collisions disabled. Any help would be greatly appreciated!

local gravel = game.Workspace.UnstablePart
local texture = gravel.Texture
local isTouched = false

local function PlayerTouched(gravel)
	if isTouched == false then
		gravel.Transparency = 0.1
		texture.Transparency = 0.1
		isTouched = true
		wait(0.2)
		gravel.Transparency = 0.2
		texture.Transparency = 0.2
		wait(0.2)
		gravel.Transparency = 0.3
		texture.Transparency = 0.3
		wait(0.2)
		gravel.Transparency = 0.4
		texture.Transparency = 0.4
		wait(0.2)
		gravel.Transparency = 0.5
		texture.Transparency = 0.5
		wait(0.2)
		gravel.Transparency = 0.6
		texture.Transparency = 0.6
		wait(0.2)
		gravel.Transparency = 0.7
		texture.Transparency = 0.7
		wait(0.2)
		gravel.Transparency = 0.8
		texture.Transparency = 0.8
		wait(0.2)
		gravel.Transparency = 0.9
		texture.Transparency = 0.9
		wait(0.2)
		gravel.Transparency = 1
		texture.Transparency = 1
		gravel.CanCollide = false
		wait(5)
		gravel.Transparency = 0
		texture.Transparency = 0
		gravel.CanCollide = true
		isTouched = false
	end
end

gravel.Touched:connect(PlayerTouched)
1 Like

The only thing I see wrong is that It may run before it is hit by a player.

Nothing is working at all? Is the localscript in StarterPack?

1 Like

So I would suggest running the touchedEvent from the server.
Eg,

local gravel = game.Workspace.UnstablePart
local event = game:GetService("ReplicatedStorage").myEvent --Path to your event

gravel.Touched:Connect(function(hit)
    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    if player then
        event:FireClient(player)
    end
end)

Then you would pick it up from the client and run it there.

I appreciate the help, but where would my code go within this?

1 Like

It makes the thing that hits is Transparent, XD:

local gravel = game.Workspace.UnstablePart
local function PlayerTouched(gravel)

image

So you would want to create a Local Script, you can place it in StarterPlayerScripts or StarterCharacterScripts.

Then you would do:

local gravel = game.Workspace.UnstablePart
local event = game:GetService("ReplicatedStorage").myEvent --Path to your event

event.OnClientEvent:Connect(function()
	gravel.Transparency = 0.1
	texture.Transparency = 0.1
	wait(0.2)
	gravel.Transparency = 0.2
	texture.Transparency = 0.2
	wait(0.2)
	gravel.Transparency = 0.3
	texture.Transparency = 0.3
	wait(0.2)
	gravel.Transparency = 0.4
	texture.Transparency = 0.4
	wait(0.2)
	gravel.Transparency = 0.5
	texture.Transparency = 0.5
	wait(0.2)
	gravel.Transparency = 0.6
	texture.Transparency = 0.6
	wait(0.2)
	gravel.Transparency = 0.7
	texture.Transparency = 0.7
	wait(0.2)
	gravel.Transparency = 0.8
	texture.Transparency = 0.8
	wait(0.2)
	gravel.Transparency = 0.9
	texture.Transparency = 0.9
	wait(0.2)
	gravel.Transparency = 1
	texture.Transparency = 1
	gravel.CanCollide = false
	wait(5)
	gravel.Transparency = 0
	texture.Transparency = 0
	gravel.CanCollide = true
end)

Like @TheZanderius recommended, I think you should carry this out on the server, and if necessary you can easily trasmit information to the client.

I don’t know how I didn’t notice that. What would fix this?

1 Like
local gravel = game.Workspace.UnstablePart
local texture = gravel.Texture
local isTouched = false

local function PlayerTouched()
	if isTouched == false then
		gravel.Transparency = 0.1
		texture.Transparency = 0.1
		isTouched = true
		wait(0.2)
		gravel.Transparency = 0.2
		texture.Transparency = 0.2
		wait(0.2)
		gravel.Transparency = 0.3
		texture.Transparency = 0.3
		wait(0.2)
		gravel.Transparency = 0.4
		texture.Transparency = 0.4
		wait(0.2)
		gravel.Transparency = 0.5
		texture.Transparency = 0.5
		wait(0.2)
		gravel.Transparency = 0.6
		texture.Transparency = 0.6
		wait(0.2)
		gravel.Transparency = 0.7
		texture.Transparency = 0.7
		wait(0.2)
		gravel.Transparency = 0.8
		texture.Transparency = 0.8
		wait(0.2)
		gravel.Transparency = 0.9
		texture.Transparency = 0.9
		wait(0.2)
		gravel.Transparency = 1
		texture.Transparency = 1
		gravel.CanCollide = false
		wait(5)
		gravel.Transparency = 0
		texture.Transparency = 0
		gravel.CanCollide = true
		isTouched = false
	end
end

gravel.Touched:connect(PlayerTouched)

also, @Turned_Away, like @TheZanderius and @tyIaur said, put this in a script in ServerScriptService!

2 Likes

It didn’t work unfortunately, no errors in output

1 Like

it is possible it is working and it just moves too fast (Not likely because 2.0 seconds is fast enough to see) to see it or it restarts on every touch. The touched event triggers INCREDIBLY fast.

This fixed the player invisibility isssue, now I just have to find out how to make it local

1 Like

Also, maybe try tweening the textures transparency, I needed to tween a lights brightness and it worked well for me (Not exactly the same thing but it should still work)

1 Like

Why do you want it local? It would be better on the server.

Because individual players triggering it would effect other players’ gameplay

1 Like

Oh, that’s right.

It should work fine on the client

EDIT: It works for me on the client.

How did you format the script?

1 Like

Just like I said:

local gravel = game.Workspace.UnstablePart
local texture = gravel.Texture
local isTouched = false

local function PlayerTouched()
	if isTouched == false then
		gravel.Transparency = 0.1
		texture.Transparency = 0.1
		isTouched = true
		wait(0.2)
		gravel.Transparency = 0.2
		texture.Transparency = 0.2
		wait(0.2)
		gravel.Transparency = 0.3
		texture.Transparency = 0.3
		wait(0.2)
		gravel.Transparency = 0.4
		texture.Transparency = 0.4
		wait(0.2)
		gravel.Transparency = 0.5
		texture.Transparency = 0.5
		wait(0.2)
		gravel.Transparency = 0.6
		texture.Transparency = 0.6
		wait(0.2)
		gravel.Transparency = 0.7
		texture.Transparency = 0.7
		wait(0.2)
		gravel.Transparency = 0.8
		texture.Transparency = 0.8
		wait(0.2)
		gravel.Transparency = 0.9
		texture.Transparency = 0.9
		wait(0.2)
		gravel.Transparency = 1
		texture.Transparency = 1
		gravel.CanCollide = false
		wait(5)
		gravel.Transparency = 0
		texture.Transparency = 0
		gravel.CanCollide = true
		isTouched = false
	end
end

gravel.Touched:connect(PlayerTouched)
1 Like

Thanks for your help Dan ㅤㅤㅤㅤㅤㅤ

1 Like