So I created a remote event script so when I touch a brick it prints hello. I just used print to try and figure out what I'm doing wrong.
Here is my script:
-- Variables -- houseprice = 250 local event = game.ReplicatedStorage:WaitForChild("PurchaseGUIEvent") -- Script -- script.Parent.Touched:Connect(function(hit) if hit:FindFirstChild("leaderstats") then if hit.leaderstats.Cash.Value >= houseprice then local player = game.Players:GetPlayerFromCharacter(hit.Parent) event:FireClient(player) end end end)
Here's what is in my local script:
local replicatedStorage = game:GetService("ReplicatedStorage") local Gui = script.Parent replicatedStorage.PurchaseGUIEvent.OnClientEvent:Connect(function() print("Hey there") end)
Whenever I touch the brick it doesn't do anything. No errors.
On script use if hit.Parent:FindFirstChild("Humanoid") then
not if hit:FindFirstChild("leaderstats")
and after this get player, check player and detect cash. and execute event
For get player with TouchEvent you need to use the hit.Parent:FindFirstChild("Humanoid")
Example:
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then print("Got player: " .. player.Name) end end end)
Here is fixed script:
-- Variables -- houseprice = 250 local event = game.ReplicatedStorage:WaitForChild("PurchaseGUIEvent") -- Script -- script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then -- Check if is a character local player = game.Players:GetPlayerFromCharacter(hit.Parent)-- Get player if player then -- If get player if player.leaderstats.Cash.Value >= houseprice then -- If cash >= of houseprice (changed hit to player) event:FireClient(player) -- Fire event. end end end end)
Hope it helped :D