How to set a part's transparency when you click your mouse with a tool activated?

I have a sand bucket in serverstorage and this inside of it:
Screen Shot 2021-08-31 at 9.41.45 PM
I have the LocalScript to play the animation when you click your miuse but i want to set the sand parts transparency so that it looks like you have sand in your bucket but i cant get this to work and i want it to be on the server so everyone can see it. Heres the localscript although i might need a regular script for the sand part:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Animator = character:WaitForChild("Humanoid"):WaitForChild("Animator")

local tool = script.Parent 

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://7378586179"

local loaded = Animator:LoadAnimation(animation)

tool.Activated:Connect(function()
	loaded:Play()
end)

local player = game.Players.LocalPlayer
local GUI = player.PlayerGui

script.Parent.Activated:Connect(function() --[[you can add a 
variable for the tool for more easy reference]]
	GUI.BucketGui.Enabled = true --[[ replace screenGui with the name of the screenGui, 
and always make sure the ScreenGui is not enabled in the first place.]]
end)

script.Parent.Unequipped:Connect(function()
	GUI.BucketGui.Enabled = false
	end)

Most of the functions and events you are using should work in a server script, so you can put that in a server script instead of a local script.

You can change the transparency property of sand parts within the Tool.Activated event.

local player = script:FindFirstAncestorWhichIsA("Player") or game:GetService("Players"):GetPlayerFromCharacter(script.Parent.Parent)
local character = player.Character or player.CharacterAdded:Wait()
local Animator = character:WaitForChild("Humanoid"):WaitForChild("Animator")

local tool = script.Parent 

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://7378586179"

local loaded = Animator:LoadAnimation(animation)
local GUI = player.PlayerGui

tool.Activated:Connect(function()
	loaded:Play()
    GUI.BucketGui.Enabled = true
end)

It animates but the sand doesn’t appear when I click

Tool.Sand.Transparency = 0 to reveal the sand
Tool.Sand.Transparency = 1 to hide it

1 Like

I know I used that and it didn’t work

But where did you use it? In the example above from

tool.Activated:Connect(function()
	loaded:Play()
    GUI.BucketGui.Enabled = true
    tool.Sand.Transparency = 0  -- add this line in
end)
1 Like

this is my script:

local player = script:FindFirstAncestorWhichIsA("Player") or game:GetService("Players"):GetPlayerFromCharacter(script.Parent.Parent)
local character = player.Character or player.CharacterAdded:Wait()
local Animator = character:WaitForChild("Humanoid"):WaitForChild("Animator")

local tool = script.Parent 

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://7378586179"

local loaded = Animator:LoadAnimation(animation)
local GUI = player.PlayerGui

tool.Activated:Connect(function()
	loaded:Play()
	GUI.BucketGui.Enabled = true
	tool.Sand.Transparency = 0
end)

local GUI = player.PlayerGui

script.Parent.Unequipped:Connect(function()
	GUI.BucketGui.Enabled = false
end)

Everything but the sand transparency part works

Your Sand is not welded to the bucket. When you equip the tool, can you still see the Sand in the Tool tree under your Character? Is it still in the same area you expected, ie contained within the bucket?
If not, then you need to weld Sand to the Handle

Screen Shot 2021-09-01 at 5.46.52 PM
Its in the tool and its in my backpack since it gets cloned from server storage to the backpack when you purchase it

I understand that, but you might find that because the Sand part is not Welded to the Handle part, that it drops out.
Play the game in Studio, locate the part in Explorer, then click the Move tool to show you where it actually is in world space. I doubt it is where you expect it to be.

1 Like

The sand may have fallen into the void if it is unanchored, collision off, and not welded to anything.

1 Like

Oh yea it isn’t there I anchored the part and now imma try welding it

After welding it it filled with sand when I clicked