-
What do I want to achieve?
So, I have this Local Script inside a union part. And in that script I have a touched event, which fires when a remote event on the server. -
What is the issue?
So the issue is that, The Touched Event is not getting fired in a Union Event.
Note that - I am using a Local Script -
What solutions have I tried so far?
Yes, I have looked for solutions on google, as well as on The Roblox Developer Forum. So upon viewing other threads/posts, they basically had a Server Script inside the union. And they also made the union unanchored. So I also made my union part unanchored. I also tried making my Local Script into Server Script. But I got more issues. So can’t do that.
Here is my Client Side Code - (It is located inside the union part)
local HasClaimed = script.Parent.Parent.Parent:WaitForChild("HasClaimed")
HasClaimed.Changed:Connect(function()
if HasClaimed.Value == true then
local PurchaseRequest = game.ReplicatedStorage.events.PurchaseRequest
local PurchaseAccept = game.ReplicatedStorage.events.PurchaseAccepted
local Owner = script.Parent.Parent.Parent.Parent.Owner
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Name == Owner.Value then
local Item = script.Parent.Parent.Item
local Price = script.Parent.Parent.Price
PurchaseRequest:FireServer(Item.Value, Price.Value)
PurchaseAccept.OnClientEvent:Connect(function()
script.Parent.Parent:Destroy()
end)
end
end)
end
end)
And Here is my Server Side Code -
-- Handles Purchasing
PurchaseRequest.OnServerEvent:Connect(function(Plr, Item, Price)
local Player = game.Players:FindFirstChild(Plr)
local Stuff = PurchasableItems:FindFirstChild(Item)
if Player.leaderstats.Cash.Value >= Price then
-- Deducting the price from the player's cash
Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value - Price
-- Making the Item Appear and Making it work
for _, v in pairs(Stuff:GetChildren()) do
if v:IsA("UnionOperation") or v:IsA("Part") then
v.Transparency = 0
v.CanCollide = true
v.CanTouch = true
elseif v:IsA("Script") then
v.Enabled = true
v.Parent:WaitForChild("Work").Value = true
end
end
-- Putting it in the BoughtItems Folder
Stuff.Parent = BoughtItems
-- Making the Button disappear
PurchaseAccepted:FireClient()
end
end)
Please Help me out here, so that I don’t have to make my local script into a Server script.
Thanks,
TSMN