I’m trying to make a mining system that awards the player currency upon mining an ore, but, the transparency of the ore seems to only be working once. Might there be a solution to this?
Serverscript that only runs once.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local OreTouchedEvent = ReplicatedStorage.OreTouchedEvent
local OreTransparency = 0
OreTouchedEvent.OnServerEvent:Connect(function(player, Ore)
local char = player.Character
local hum = char:FindFirstChildOfClass("Humanoid")
if hum then
local pickaxe = char:FindFirstChild("Pickaxe")
if pickaxe then
for _, v in ipairs(Ore:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "Hitbox" then
v.Transparency = OreTransparency + 0.25
wait(2)
end
end
end
end
end)
The wait(2) is there as a way to limit how many times the model goes transparent. Since if it wasn’t there, the ore would vanish in an instant and I don’t want this to happen
local Players = game:GetService(“Players”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local OreTouchedEvent = ReplicatedStorage.OreTouchedEvent
local OreTransparency = 0
local debounce = false
OreTouchedEvent.OnServerEvent:Connect(function(player, Ore)
local char = player.Character
local hum = char:FindFirstChildOfClass(“Humanoid”)
if hum then
local pickaxe = char:FindFirstChild(“Pickaxe”)
if pickaxe then
if debounce == false then
debounce = true
for _, v in ipairs(Ore:GetChildren()) do
if v:IsA(“BasePart”) and v.Name ~= “Hitbox” then
v.Transparency = OreTransparency + 0.25
wait(2)
debounce = false
end
end
end
end
end
end)
Try inserting prints into the code to see what runs, I’d also like to see how you’re calling the event and why you’re using a remote event? I’d imagine you’d detect the touch on the server and use a bindable event instead of client sided detection then using remotes?
Sure. I’ll show you where the remote event is connected to! In fact, there’s four which call the same remote event. But, I’ll just show you both.
local IronOre = game.Workspace.IronOre
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Hitbox = script.Parent:WaitForChild("Hitbox")
local replicatedStorage = game:GetService("ReplicatedStorage")
local OreTouchedEvent = replicatedStorage.OreTouchedEvent
Hitbox.Touched:Connect(function(player)
OreTouchedEvent:FireServer(IronOre)
end)
local GoldOre = game.Workspace.GoldOre
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Hitbox = script.Parent:WaitForChild("Hitbox")
local replicatedStorage = game:GetService("ReplicatedStorage")
local OreTouchedEvent = replicatedStorage.OreTouchedEvent
Hitbox.Touched:Connect(function(player)
OreTouchedEvent:FireServer(GoldOre)
end)
What are you using for these hitboxes? Also when I say hit once, i mean if the same part touches the hitbox multiple times it ignores its touches besides for the first hit.
That’s pretty strange. Try changing V.Transparency = OreTransparency + 0.25 to V.Transparency += 0.25? Other than that I would seriously recommend switching from remote events to bindable events and having everything done on the server.