I want to make it so when you touch the crystal, you gain +1 of a value, then the crystal destroys itself and fires a remote to the client that tells another script to subtract a value. These crystals are located in ReplicatedStorage and get parented to workspace over time.
In workspace, the objects have the script inside of them, but when I touch them nothing happens
script.Parent.Prim.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local s = plr:WaitForChild("Data"):WaitForChild("Runes")
local crystal = s:WaitForChild("NormalCrystal")
crystal.Value += 1
game.ReplicatedStorage.Remotes.CrystalRemove:FireClient(plr)
script.Parent:Destroy()
end
end)
so here is the issue: The Touched event might not be firing as expected. ensure that the part you’re touching has the cancollide property set to true.
here is the issue: you’re incrementing the crystal.Value by 1. This should work if the NormalCrystal exists in the player’s data.You have to ensure normal crystal is correctly set up in the player’s data structure. so remember to check hierarchy, data structure, and ensure that relevant parts exist. and also your firing a crystal remove RemoteEvent to the client.Make sure this event is properly handled on the client side.
If the script is a server Script then using WaitForChild might be causing the problem, so I suggest doing this instead:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
script.Parent.Prim.Touched:Connect(function(hit)
local model = hit:FindFirstAncestorOfClass("Model")
if model then
local player = Players:GetPlayerFromCharacter(model)
if player then
player.Data.Runes.Crystal += 1
ReplicatedStorage.Remotes.CrystalRemove:FireClient(player)
script.Parent:Destroy()
end
end
end)
Otherwise if it’s a LocalScript, do remember that they don’t work if they’re inside of Workspace and even if they did changing the value using one won’t make it change in the server as well
nah I figured out the issue, its because apparently serverscripts break when they go from replicated storage to workspace so I just used remote events and fixed it